% Programming and Numerical Methods
% MSc in Computational and Applied Physics

% Code 11:  Composite trapezoidal formula
% A. Meseguer (2007)

  function integ = tcf(a,b,m,myfun)
 
  H = (b-a)/m ; x = a + H*[0:m]' ;
  f = feval(myfun,x) ;
  integ = H*(.5*f(1) + sum(f(2:end-1)) + .5*f(end)) ;


