function integral = traptd2(f,a,b,n) % Approximates the definite integral of funct from a to b % using the n-point trapezoidal rule % T. DeLillo, Math 451, fall 2001 x=linspace(a,b,n); h=(b-a)/(n-1); fval = feval(f,x); integral=(.5*fval(1)+sum(fval(2:n-1))+.5*fval(n))*h;