% Testing of the clamped spline
% For this test, we generate the spline from a small set of
% values from a known function. We also use the exact derivative
% for the endpoint slope values.
% We then use the spline % to interpolate a larger set of values
% and compute the relative error at this larger set of points.
clear
load testdata.dat % Table 1 data to 5 digits instead of 3
xdata = testdata(:,1);
Tdata = testdata(:,2);
% Test clampled spline using known exact derivatives. m1 and m2
% are the exact slopes at the endpoints.
x1 = xdata(1);
m1 = x1*exp(-x1)*(2-x1)+exp(x1);
p = length(xdata);
x1 = xdata(p);
m2 = x1*exp(-x1)*(2-x1)+exp(x1);
Ttemp = [m1; Tdata; m2]; % Prepend and append endpoint slopes
% to the Tdata points.
TC = spline(xdata,Ttemp); % Evaluate clampled spline structure
xval = linspace(-1,2,51)'; % Generate a large set of test points
tcval = ppval(TC,xval); % Interpolate at these test points using the spline
Texact = xval.^2.*exp(-xval) + exp(xval);
error = (tcval - Texact)./Texact;
[xval tcval Texact error]