% Purpose: Integration of a function by extended
% trapezoidal rule.
% Synopsis: I = trapez(f_name,a,b,n)
% f_name: function M-file name of integrand
% a: lower limit
% b: upper limit
% n: number of intervals

function I = trapez(f_name,a,b,n)
h=(b-a)/n;
x=a+(0:n)*h;
f=feval(f_name,x);
I=h*(sum(f)-0.5*(f(1)+f(length(f))));