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

% Code 12:  Composite Cavalieri-Simpson formula
% A. Meseguer (2007)
  function integ = mpcf(a,b,m,myfun) 
 
  H = (b-a)/m ; x = a + [0:2*m]'*H/2 ;
  f = feval(myfun,x) ;
  integ = (H/6)*(f(1)+2*sum(f(3:2:end-2))+4*sum(f(2:2:end-1)) + f(end));


