% numerical intergration clear all close all h=.1; x=pi/2:h:2*pi; y=sin(x); figure(1) plot(x,y) % the trapz command- gives you the definite integral over the whole vector yint=trapz(x,y); % the cumtrapz command- gives you the integral as a vector of same length % as x yintcum=cumtrapz(x,y); hold on plot(x,yintcum,'r') % the quad function -uses recursive Simpsons rule algorithm % likes functions as inputs a=8; yint2=quad(inline('exp(x)'),-1,1); %when using inline, always use x as the variable. % using quad with a function call for i=1:5 newint(i)=quad(@(x)exponential(x,i),0,1); end % dblquad- double integration [x,y]=meshgrid(-pi:.1:pi, -pi:.1:pi); %x=-1:.05:1; %y=-1:.05:1; z=sincos(x,y); %function call using sincos.m, you can also use dblgauss.m figure(2) plot3(x,y,z) gaussint=dblquad('sincos(x,y)',-1,1,-1,1); %there is a triplequad