function showadapt(tol)
%SHOWADAPT demonstrate the performance of adaptsimp

if nargin == 0
 tol = .001;
end

% initialize function evaluation counter and graphics window
global nfun; nfun = 0; clf; drawnow; hold on;

% give the exact value of the integral if known
% (here we use quad8, Matlab's high order adaptive quadrature routine)
exact = quad8('humps',0,3,1.e-10);

% for animated display fix axes
axis([0 3 -20 100]);

% set function, limits of integration and tolerance
fun = 'humpsp'; a = 0; b = 3;
x = linspace(a,b,300);
plot(x,humps(3-x),'g');

% call adaptsmp and display the results
approx = adaptsmp(fun,a,b,tol);
err = exact - approx;
fprintf('\n exact integral =    %17.10e\n',exact);
fprintf(' computed integral = %17.10e\n',approx);
fprintf(' tolerance =           %13.2e\n',tol);
fprintf(' error =               %13.2e\n',err);
fprintf(' relative error =      %13.2e\n',err/approx);
fprintf(' function evaluations = %d\n\n',nfun);
