%ADAPT_EX        Script M-file to illustrate ADAPT.

fun = inline('1./((x-0.3).^2+0.03) + 1./((x-0.8).^2+0.1)-4');
a = 0; b = 1; tol = 8e-3;
global xpts      % Give access to grid, for later plotting.
[q,fcount] = adapt(fun,a,b,tol)
x = linspace(a,b,100); fx = fun(x); fxpts = fun(xpts);
plot(x,fx,xpts,fxpts,'o')
title(['fcount = ' num2str(fcount)]); hold on
% Plot x-points chosen by ADAPT as ticks on x-axis.
z = [0 max(fxpts)*4.25/100];
for i=1:max(size(xpts))
    plot( [ xpts(i); xpts(i) ], z )
end
hold off
