% Clenshaw-Curtis non-periodic quadrature demo on interval [-1,1]
% Uses clencurt.m          Barnett 5/21/13

a = 0.5;  % singularity distance parameter (+-ia),  eg 0.5
f = @(x) a./(a^2+x.^2);
fint = 2*atan(1/a);
ns = 5:5:70; es = 0*ns;  % n's and errors
for i=1:numel(ns), n = ns(i);
  [x w] = clencurt(n-1);  % get n-pt CC nodes and weights
  es(i) = dot(w,f(x)) - fint;   % do the integral & compute error
end
figure; semilogy(ns,abs(es),'+-'); xlabel('n'); ylabel('err'); % exp conv
axis([min(ns) max(ns) 1e-16 1]);

%hold on; plot(ns, exp(-asinh(a)*ns), 'r-');  % predicted exp conv rate

