function census_demo
%
% This demonstrates the behavior of polynomials that interpolate 
% selected census values, starting with the year 2000 value. The 
% user is queried for the number of values to be interpolated. 
%

census_data = [1900   75994600; 
	       1910   91972300; 
	       1920  105711000; 
	       1930  122775000; 
	       1940  131669000; 
	       1950  150697000; 
	       1960  179323000; 
	       1970  203235000; 
	       1980  226505000; 
	       1990  249633000; 
	       2000  281422000]; 

x = sort(census_data(:,1),1,'descend');
y = sort(census_data(:,2),1,'descend'); 

xlow = 1880; xhigh = 2020; 
ylow = 0; yhigh = 400000000; 

figure(1); clf; hold on; 
plot(x,y,'g*'); 
axis([xlow xhigh ylow yhigh]); 

h = 100\(xhigh - xlow); 
xx = [xlow:h:xhigh];

d = div_dif(x,y);

npts = input('Type the number of census values <= 11 (or -1 to quit):'); 
while npts > 0 
  figure(1); 
  delete(findobj('Type','line','Color','b'));
  delete(findobj('Type','line','Color','r'));
  delete(findobj('Type','line','MarkerFaceColor','r'));
  ppval = p_eval(xx,x(1:npts),d(1:npts)); 
  plot(xx,ppval,'b');
%  pval = p_eval(x(1:npts),x(1:npts),d(1:npts)); 
  plot(x(1:npts),y(1:npts),'o',...
         'MarkerSize',4,'MarkerFaceColor','r',...
         'MarkerEdgeColor','k','LineWidth',1.8);
  title(['Census data interpolation: ', num2str(npts),' points.']); 
  npts = input('Type the number of census values <= 11 (or -1 to quit):'); 
end

