function runge_demo
%
% This demonstrates the behavior of interpolating polynomials 
% on equally spaced interpolation points for the Runge function. 
%
xleft = -1.1; xright = 1.1;
ylow = -1; yhigh = 2;
h = 1/100;
xx = [xleft:h:xright];
Rvals = 1./(1+25*xx.^2);
figure(1); clf; hold on; 
plot([xleft xright],[0 0],'k',...
     [0 0],[ylow yhigh],'k','LineWidth',1);
plot(xx,Rvals,'b','LineWidth',1); 
axis([xleft xright ylow yhigh]); 
dgr = input('Type the degree of the interpolating polynomial (or -1 to quit):'); 
npts = dgr + 1;
while npts > 0 
  h = 2/(npts - 1); 
  x = [-1:h:1]; 
  y = 1./(1+25*x.^2);
  y = div_dif(x,y);
  ppval = p_eval(xx,x,y);
  delete(findobj('Type','line','Color','r'));
  delete(findobj('Type','line','MarkerFaceColor','r'));
  figure(1); plot(xx,ppval,'r');
  pval = p_eval(x,x,y);
  plot(x,pval,'o',...
         'MarkerSize',4,'MarkerFaceColor','r',...
         'MarkerEdgeColor','k','LineWidth',1.8);
  title(['Polynomial interpolation: degree ', num2str(dgr)]);
  dgr = input('Type the degree of the interpolating polynomial (or -1 to quit):'); 
  npts = dgr + 1;
end
