function y = EvaluateClampedSplines(xnew,x,Splines)
%
% Evaluate function values at selected points xnew
% given nodal points x and splines. 
% We assume x is arranged from smallest to biggest. 
%
% Written by Ming Gu for Math 128A, Fall 2008
% Updated by Ming Gu for Math 128A, Spring 2015
%
a = Splines.a;
b = Splines.b;
c = Splines.c;
d = Splines.d;
n = length(x)-1;
m = length(xnew);
y = NaN(m,1);
for k=1:m
    xnewk = xnew(k);
%
% Make sure points are inside of the range of nodal points
%
    if ((xnewk < x(1)) | (xnewk > x(n+1)))
        error('xnew points out of range');
    end
    j =min(max(find(xnewk>= x)),n);
    xdif = xnewk-x(j);
%
% Evaluate Splines using Horner's method.
%
    y(k) = a(j)+xdif*(b(j)+xdif*(c(j)+d(j)*xdif));
end



    
    
    
