function S=simpson1(x,y) n=length(x) h=x(2)-x(1) s=y(1)+y(n) for i=2:2:n-1 s=s+4*y(i) endfor for i=3:2:n-2 s=s+2*y(i) endfor S=h/3*s endfunction