function v = natsplfun2(x, y, b, c, d, u)
%NATSPLFUN2  Natural cubic spline function.
%  v = natsplfun(x, y, b, c, d, u) returns w(k) = S'(u(k)).

    % Find subinterval indices k so that x(k) <= u < x(k+1)

    n = length(x); 
    k = ones(size(u));
    for j = 2:n-1
        k(x(j) <= u) = j;
    end

    % Evaluate spline

    s = u - x(k);
    v = b(k) + s.*(2*c(k) + 3*s.*d(k));
end
