function t=trapez(a,b,n) h=(b-a)/n; x=a:h:b; y=f(x); t=y(1)+y(n+1); for i=2:n t=t+2*y(i); endfor t=t*h/2; endfunction