A cubic spline is a spline constructed of piecewise third-order polynomials which pass through a set of
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
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
points
.
Following Bartels et al. (1998, pp. 10-13), let the
th
piece of the spline be represented by
|
(1)
|
where is a parameter
and
,
...,
. Then
|
(2)
| |||
|
(3)
|
Taking the derivative of in each
interval then gives
|
(4)
| |||
|
(5)
|
Solving (2)-(5) for ,
,
, and
then gives
|
(6)
| |||
|
(7)
| |||
|
(8)
| |||
|
(9)
|
Now require that the second derivatives also match at the points, so
|
(10)
| |||
|
(11)
| |||
|
(12)
| |||
|
(13)
|
for interior points, as well as that the endpoints satisfy
|
(14)
| |||
|
(15)
|
This gives a total of
equations for the
unknowns.
To obtain two more conditions, require that the second derivatives at the endpoints
be zero, so
|
(16)
| |||
|
(17)
|
Rearranging all these equations (Bartels et al. 1998, pp. 12-13) leads to the following beautifully symmetric tridiagonal system
|
(18)
|
If the curve is instead closed, the system becomes
|
(19)
|