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

% Code 13:  4th order Composite Newton - Cotes quadrature formula
% Closed prescription
% A. Meseguer (2007)

  function integ = cnc4f(a,b,m,myfun)

  A4 = (1/45)*[14 64 24 64 14]' ;
  H = (b-a)/m ;
  y = a + [0:m]'*H ;
  integ = 0 ;  

  for jj = 0:m-1
   aj = a + jj*H ; bj = a + (jj+1)*H ;
   h = (bj-aj)/4 ; x = aj + [0:4]'*h ;
   f = feval(myfun,x) ;
   integ = integ + h*sum(A4.*f) ; 
  end





