%Function for evaluating cubic spline using coefficient calculated
% using cubic_spline function. Function needs following entries, range
% over which spline plotted, a,b,c,d the calculated coefficient, and x and
% y data.
function f_interp = cubic_spline_eval(xaxis,a,b,c,d,x,y)
j = 0;
f_interp = zeros(max(size(xaxis)),1);
for xi = xaxis %
j = j+1;
seg = sum(xi>=x);
if seg > length(a)
if c(1) == 0
seg = length(a);
else
f_interp(j) = y(end);
continue
end
elseif seg < 1
if c(1) == 0 % 2nd deriv at start = 0
seg = 1;
else
f_interp(j) = y(1);
continue
end
end
f_interp(j) = a(seg) + b(seg)*(xi-x(seg)) + c(seg)*(xi-x(seg))^2 +d(seg)*(xi-x(seg))^3;
end
