function S=simpson2(x,y) n=length(x) h=x(2)-x(1) s=y(1)+y(n) for i=2:n-1 if rem(i,2)==0 s=s+4*y(i) else s=s+2*y(i) endif endfor S=h/3*s endfunction