%
% Trapezoidal composite rule
%
% fun = funtion to integrate
% a   = left boundary
% b   = right boundary
% n   = number of interval
%
function RES = trapPlot( fun, a, b, n)
  h     = (b-a)/n ;
  nodes = [a:h:b] ;
  yvals = feval( fun, nodes ) ;
  X     = [a:(b-a)/1000:b] ;
  Y     = feval( fun, X ) ;

  % plot function 
  plot( X, Y ) ;

  hold on ;
  % plot trapezioid with alternatig colours
  for i=1:n
    h = area( nodes(i:i+1), yvals(i:i+1) ) ;
    if mod(i,2) == 1
      set(h(1),'FaceColor',[.5 .8 .9]) ;
    else
      set(h(1),'FaceColor',[.9 .8 .7]) ;
    end
  end
  
  % plot function 
  plot( X, Y ) ;

  hold off ;
end
