function ShowCompleteSpline()
% Interpolate f(x) = sin(x) across [0,2pi] using two different splines.
n = 13;
close all
z = linspace(0,2*pi,300)';
fVals = sin(z);

% First, let us look at the not-a-knot spline...
x = linspace(0,2*pi,n)';
y = sin(x);
S = spline(x,y);
SVals = ppval(S,z);
plot(z,fVals,x,y,'o',z,SVals)
[x,rho] = unmkpp(S);
% Slope at x = 0. Since the leftmost cubic is
% rho(1,1)(x-x1)^3 + rho(1,2)(x-x1)^2 + rho(1,3)(x-x1) + rho(1,4)
% it follows that
spL = rho(1,3);
% Slope at x = 2pi. Since the rightmost cubic is
% rho(m,1)(x-xm)^3 + rho(m,2)(x-xm)^2 + rho(m,3)(x-xm) + rho(m,5)
% where
m = n-1;
% we have
spR = 3*rho(m,1)*(x(n)-x(m))^2 + 2*rho(m,2)*(x(n)-x(m)) + rho(m,3);
title(sprintf('s''(0) = %6.3f s''(pi) = %6.3f',spL,spR),'fontsize',14)
xlabel(sprintf('Not-a-knot spline interpolant of sin(x). n = %2d',n),'fontsize',14)
axis equal

% Now look at the complete spline with end slopes forced to 1.
SpL = 1;
SpR = 1;
S = spline(x,[SpL;y;SpR]);
SVals = ppval(S,z);
figure
plot(z,fVals,x,y,'o',z,SVals)
[x,rho] = unmkpp(S);
% Slope at x = 0. Since the leftmost cubic is
% rho(1,1)(x-x1)^3 + rho(1,2)(x-x1)^2 + rho(1,3)(x-x1) + rho(1,4)
% it follows that
spL = rho(1,3);
% Slope at x = 2pi. Since the rightmost cubic is
% rho(m,1)(x-xm)^3 + rho(m,2)(x-xm)^2 + rho(m,3)(x-xm) + rho(m,5)
% where
m = n-1;
% we have
spR = 3*rho(m,1)*(x(n)-x(m))^2 + 2*rho(m,2)*(x(n)-x(m)) + rho(m,3);
title(sprintf('s''(0) = %6.3f s''(pi) = %6.3f',spL,spR),'fontsize',14)
xlabel(sprintf('Complete spline interpolant of sin(x). n = %2d',n),'fontsize',14)
axis equal