function [A]=simps(x,y) % Finds the area under a curve y(x) using Simpson's 2nd rule. % x must have same step spacing, uneven length and be larger than % equal to 3. % /by Gloria Stenfelt Feb. 2015 @hib.no n=length(x); if mod(n,2)==0 || n<3 disp('ERROR using simps: The length of vector x must be odd and at least 3.') A=nan; return end i=1:2:length(x)-2; j=2:2:length(x)-2; s424(i)=4; s424(j)=2; sf=[1 s424 1]; % Simpson factor vector s=x(2)-x(1); A=s/3 * (sf*y');