close all, clear all

d = domain(-1,1);
x = chebfun('x'); 
f = 1./(1+25*x.^2);
%f = exp(abs(x));
%f = exp(x);


figure(1)
s = linspace(-1,1,8); p = interp1(s,f,d);
hold off, plot(f), hold on, plot(p,'r'), grid on
plot(s,p(s),'.r'), axis([-1 1 -1 3]), FS = 'fontsize';
title('Equispaced interpolation of Runge function, 8 points',FS,9)


figure(2)
s = linspace(-1,1,16); p = interp1(s,f,d);
hold off, plot(f), hold on, plot(p,'r'), grid on
plot(s,p(s),'.r'), axis([-1 1 -1 3])
title('Equispaced interpolation of Runge function, 16 points',FS,9)


figure(3)
s = linspace(-1,1,20); p = interp1(s,f,d);
hold off, plot(f), hold on, plot(p,'r'), grid on
plot(s,p(s),'.r'), axis([-1 1 -1 3])
title('Equispaced interpolation of Runge function, 20 points',FS,9)


figure(4)
ee = []; nn = 2:2:50;
for np = nn
  s = linspace(-1,1,np); p = interp1(s,f,d);
  ee = [ee norm(f-p,inf)];
end
hold off, semilogy(nn,ee,'.-'), grid on, %axis([0 50 5e-2 2e6])
xlabel n+1, title('Divergence as n+1 -> \infty',FS,9)

