spline

gives values and 1st, 2nd, 3rth derivatives of a cubic spline

Contents

Syntax

[y, dy, ddy, dddy] spline(x, knots, Dy1, Dyk)

Description

Calculates (natural or clamped) the ordinates of a cubic spline, first three derivatives; clamping can be none, left, right, left & right; outside the knot-abscissa-range the spline is linear, also if clamped; spline(x, xy, [], []) is identical to spline(x, xy) Cubic splines are piece-wise cubic polynomials between knots, and linear outside the knots, such that the spline is differentiable everywhere. Natural cubic splines have a second derivative equal to zero at the first and last knot; the first derivative is differentable everywhere, the second derivative is continuous, and the third derivative is piecewise constant and not continuous. Left and/or right clamped cubic splines have a prescribed first derivative at the first and/or last knot; the second derivative at these knots is (generally) not equal to zero, while it is outside the knot-range. The spline is interpolating, see knot for obtaining knot coordinates of a smoothing spline. The natural cubic spline is selected by default, but it can optionally be clamped left and/or right.

Input:

Output

Remarks

cf spline1 for integration; rspline for roots; espline for local extremes.

Example of use

x = (1:10)'; y = 3*(x+.1*rand(10,1)).^2;: k = knot(0.5+[0 2 5 7]',[x,y]); [Y, dY, ddY, dddY] = spline(x,k); iY = ispline(x,k); rspline(k,5)

Example of use of clamps

Y = spline(x,k,0) (left clamp); Y = spline(x,k,[],0) (right clamp); Y = spline(x,k,0,0) (left and right clamp) See mydata_spline and mydata_smooth for further illustrations.