
n = 15;
x = (-n:1:n)'/n;
N = 2*n + 1;
alpha = 0.2;
f = 1./(alpha+x.^2);

df = [-2*x(1)/((alpha+x(1)^2)^2); -2*x(end)/((alpha+x(end)^2)^2)];

Splines = ClampedSplines(x,f,df);
xnew = sort(2*rand(n,1)-1,'ascend');
xnew = xnew /max(abs(xnew));
Spln = EvaluateClampedSplines(xnew,x,Splines);
ftrue  = 1./(alpha+xnew.^2);

figure(1);
clf;
xx = (-1000:1000)/1000;
fxx = 1./(alpha+xx.^2);
plot(xx,fxx,'b-');
hold on
plot(xnew,Spln,'rd');
title('Spline Interpolation (red) vs. exact function (blue) for 1/(0.2+x^2) on [-1, 1], 31 points');

print('-dpsc',['ClampedSpexp.ps'])
cmd = cat(2,'ps2pdf ', [' ClampedSpexp.ps'], [' ClampedSpexp.pdf']);
[r,s]= system(cmd);


dff = abs(ftrue-Spln);
figure(2);
clf;
semilogy(xnew,dff,'b.-');
title('Spline Interpolation Error, semilog scale');

print('-dpsc',['ClampedSpexpError.ps'])
cmd = cat(2,'ps2pdf ', [' ClampedSpexpError.ps'], [' ClampedSpexpError.pdf']);
[r,s]= system(cmd);



