
%
% Interpolation Demo Code
%

format compact; format longe; hold off; close all


k=0;
for N=1:100; n=10*N+1; k=k+1;

   a=0;b=2;
   [z] =zuni(N); x =a + .5*(b-a)*(z+1);   % Uniformly-spaced nodes
   [zz]=zuni(n); xx=a + .5*(b-a)*(zz+1);  % Uniformly-spaced sample points

   f =cos(exp(x));
   ff=cos(exp(xx));

   Jl=lin_interp_mat(xx,x); p=Jl*f;
   
   plot(xx,ff,'r-',x,f,'ro',xx,p,'b-'); drawnow

   err_lin_interp=max(abs(p-ff))/max(abs(ff)); % Save Error
   eln(k)=err_lin_interp; nn(k)=N;
end;
title('Linear Interpolant for cos(e^x)','FontSize',24)
xlabel('x','FontSize',24); ylabel('f(x)','FontSize',24);axis square;
set (gcf,'color',[1 1 1]) % set the background color to white
print -dpng 'interp.png'


figure
loglog(nn,eln,'ro',nn,22*nn.^(-2),'k--')
title('Interpolation Error for cos(e^x)','FontSize',24)
xlabel('n','FontSize',24); ylabel('max |f(x)-p(x)|','FontSize',24);axis square;
text(2.5,5,'Slope = -2','FontSize',20)
set (gcf,'color',[1 1 1]) % set the background color to white
print -dpng 'interp_err.png'


