% script: N4.m
% description: script for exercise N4

PPfcns  % load up the PP library
knotnum = [6,11,21]; % knot numbers for h = 1,1/2,1/4
x = 0:.001:5; % grid points for error evaluation
err = zeros(size(knotnum)); % error vector
for j = 1:3
  knots = linspace(0,5,knotnum(j));
  f = 1./(1+knots.^2); % function value at knots
  fp = -2*knots./(1+knots.^2).^2; % function derivative value at knots
  pp = HCpp(knots,f,fp); % generate Hermite cubic p.p.
  err(j) = norm(1./(1+x.^2)-PPeval(pp,x),inf); % calculate error at x
end
% display the ratios
[err(1)/err(2),err(2)/err(3)]
