%MATLAB version of the FORTRAN script for example 6.13 on pages 265f in
%conte/deboor
%
%  Reference:
%
%    Samuel Conte, Carl de Boor,
%    Elementary Numerical Analysis,
%    Third Edition,
%    SIAM, 2017,
%    ISBN: 978-1-611975-19-2.
%
NPMAX = 100; 
X = -1:.1:1;  F = fix(exp(X)*100+.5)/100; W = ones(size(X)); 
  W = ones(size(X)); 
for NTERMS=1:6
   [po, ERROR] = ORTPOL( X , F , W , NTERMS );
   if NTERMS==4, p3 = ORTVAL(po,X); end
   if NTERMS==5, p4 = ORTVAL(po,X); end
   plot(X,ERROR)
   pause
end

disp(['    x        p_3(x)        (f-p_3)(x)      ', ...
                   'p_4(x)        (f-p_4)(x)       exp(x)'])
fprintf('%7.1f %12.5f  %14.3e  %12.5f  %14.3e  %12.5f \n', ...
         [X;p3;F-p3;p4;F-p4;exp(X)])
