TOPICS
Search

Cubic Spline


CubicSpline

A cubic spline is a spline constructed of piecewise third-order polynomials which pass through a set of m control points. The second derivative of each polynomial is commonly set to zero at the endpoints, since this provides a boundary condition that completes the system of m-2 equations. This produces a so-called "natural" cubic spline and leads to a simple tridiagonal system which can be solved easily to give the coefficients of the polynomials. However, this choice is not the only one possible, and other boundary conditions can be used instead.

Cubic splines are implemented in the Wolfram Language as BSplineCurve[pts, SplineDegree -> 3].

Consider 1-dimensional spline for a set of n+1 points (y_0,y_1,...,y_n). Following Bartels et al. (1998, pp. 10-13), let the ith piece of the spline be represented by

 Y_i(t)=a_i+b_it+c_it^2+d_it^3,
(1)

where t is a parameter t in [0,1] and i=0, ..., n-1. Then

Y_i(0)=y_i=a_i
(2)
Y_i(1)=y_(i+1)=a_i+b_i+c_i+d_i.
(3)

Taking the derivative of y_i(t) in each interval then gives

Y_i^'(0)=D_i=b_i
(4)
Y_i^'(1)=D_(i+1)=b_i+2c_i+3d_i.
(5)

Solving (2)-(5) for a_i, b_i, c_i, and d_i then gives

a_i=y_i
(6)
b_i=D_i
(7)
c_i=3(y_(i+1)-y_i)-2D_i-D_(i+1)
(8)
d_i=2(y_i-y_(i+1))+D_i+D_(i+1).
(9)

Now require that the second derivatives also match at the points, so

Y_(i-1)(1)=y_i
(10)
Y_(i-1)^'(1)=Y_i^'(0)
(11)
Y_i(0)=y_i
(12)
Y_(i-1)^('')(1)=Y_i^('')(0),
(13)

for interior points, as well as that the endpoints satisfy

Y_0(0)=y_0
(14)
Y_(n-1)(1)=y_n
(15)

This gives a total of 4(n-1)+2=4n-2 equations for the 4n unknowns. To obtain two more conditions, require that the second derivatives at the endpoints be zero, so

Y_0^('')(0)=0
(16)
Y_(n-1)^('')(1)=0.
(17)

Rearranging all these equations (Bartels et al. 1998, pp. 12-13) leads to the following beautifully symmetric tridiagonal system

 [2 1     ; 1 4 1    ;  1 4 1   ;   1 4 1  ; | ... ... ... ... ... ...;     1 4 1;      1 2][D_0; D_1; D_2; D_3; |; D_(n-1); D_n]=[3(y_1-y_0); 3(y_2-y_0); 3(y_3-y_1); |; 3(y_(n-1)-y_(n-3)); 3(y_n-y_(n-2)); 3(y_n-y_(n-1))].
(18)

If the curve is instead closed, the system becomes

 [4 1     1; 1 4 1    ;  1 4 1   ;   1 4 1  ; | ... ... ... ... ... ...;     1 4 1; 1     1 4][D_0; D_1; D_2; D_3; |; D_(n-1); D_n]=[3(y_1-y_n); 3(y_2-y_0); 3(y_3-y_1); |; 3(y_(n-1)-y_(n-3)); 3(y_n-y_(n-2)); 3(y_0-y_(n-1))].
(19)

See also

Bézier Curve, Spline, Thin Plate Spline

Explore with Wolfram|Alpha

References

Bartels, R. H.; Beatty, J. C.; and Barsky, B. A. "Hermite and Cubic Spline Interpolation." Ch. 3 in An Introduction to Splines for Use in Computer Graphics and Geometric Modelling. San Francisco, CA: Morgan Kaufmann, pp. 9-17, 1998.Burden, R. L.; Faires, J. D.; and Reynolds, A. C. Numerical Analysis, 6th ed. Boston, MA: Brooks/Cole, pp. 120-121, 1997.Press, W. H.; Flannery, B. P.; Teukolsky, S. A.; and Vetterling, W. T. "Cubic Spline Interpolation." §3.3 in Numerical Recipes in FORTRAN: The Art of Scientific Computing, 2nd ed. Cambridge, England: Cambridge University Press, pp. 107-110, 1992.

Referenced on Wolfram|Alpha

Cubic Spline

Cite this as:

Weisstein, Eric W. "Cubic Spline." From MathWorld--A Wolfram Web Resource. https://mathworld.wolfram.com/CubicSpline.html

Subject classifications