clear;
clf;

for N = logspace(1,6,20)
  
  %% create the grid and function to integrate
  x = linspace(0,10,N);
  f = exp(-2*x);
  
  res = 1/2*(1-exp(-2*10));    %% analytical result
  err = abs(res-trapz(x,f));   %% error in numerical result
  loglog(N,err,'ko')
  hold on
  
end


%% predicted scaling for trapezoid rule
N = logspace(1,6,20);
loglog(N,N.^-2);
text(200,1e-6,'~N^{-2}','FontSize',16)

set(gca,'FontSize',14)
xlabel('N')
ylabel('Error')
