function A=comptrap(f,a,b,m) %Approximates the integral of f over [a,b] using m+1 points. h=(b-a)/m; x=linspace(a,b,m+1); y=f(x); if m>1 A=(h/2)*(y(1)+y(m+1)+2*sum(y(2:m))); else A=(h/2)*(y(1)+y(2)); end