function [s]=integrate(x,y); % MATLAB HELP: % % [s]=integrate(x,y); % % compute the integral of y(x) from min(x) to max(x) % % aaron birch may 22 2002 % % make sure we have columns % x=make_column(x); y=make_column(y); [N M]=size(x); s=0; fav=0.5*(y(1:M-1)+y(2:M)); dx=x(2:M)-x(1:M-1); s=sum(fav.*dx); function [x]=make_column(x); % % [x]=make_column(x); % % make x into a column vector. don't use this with matrices. [a,b]=size(x); if (a~=1) x=x.'; %% careful here ! need non-conjugate transpose ! end;