%MATLAB version of the FORTRAN program for Example 6.15 on page 287 of conte/deboor
%  piecewise cubic Hermite interpolation at equally spaced points.
%
%  Reference:
%
%    Samuel Conte, Carl de Boor,
%    Elementary Numerical Analysis,
%    Third Edition,
%    SIAM, 2017,
%    ISBN: 978-1-611975-19-2.
%
F = @(y) 1./(1+y.*y);

disp('  N      MAXIMUM ERROR ')
for N=2:2:16
  X = (10/N)*(0:N) - 5; C = zeros(2,N+1);
  C(1,:) = F(X); C(2,:) = -2*X.*F(X).^2;  % that's the derivative of F
  pc = CALCCF(X,C);
      % estimate the max interpolation error
  xx = -5:.1:5;
  fprintf(' %2d    %15.7e \n',[N,max(abs(F(xx)-PCUBIC(pc,xx)))])
end
