Wikipedia / Spline interpolation
Wikipedia / Spline interpolation
In the mathematical field of numerical analysis, spline interpolation is a form of interpolation where the interpolant is a special type of piecewise polynomial called a spline. That is, instead of fitting a single, high-degree polynomial to all of the values at once, spline interpolation fits low-degree polynomials to small subsets of the values, for example, fitting nine cubic polynomials between each of the pairs of ten points, instead of fitting a single degree-nine polynomial to all of them. Spline interpolation is often preferred over polynomial interpolation because the interpolation error can be made small even when using low-degree polynomials for the spline. Spline interpolation also avoids the problem of Runge's phenomenon, in which oscillation can occur between points when interpolating using high-degree polynomials.
Introduction
Originally, spline was a term for elastic rulers that were bent to pass through a number of predefined points, or knots. These were used to make technical drawings for shipbuilding and construction by hand, as illustrated in the figure.
.
The curvature is defined as
to be continuous everywhere, including at the knots. Each successive polynomial must have equal values (which are equal to the y-value of the corresponding datapoint), derivatives, and second derivatives at their joining knots, which is to say that
This can only be achieved if polynomials of degree 3 (cubic polynomials) or higher are used. The classical approach is to use polynomials of exactly degree 3 — cubic splines.
In addition to the three conditions above, a natural cubic spline.
In addition to the three main conditions above, a clamped cubic spline is the derivative of the interpolated function.
In addition to the three main conditions above, a not-a-knot spline.
Algorithm to find the interpolating cubic spline
at its endpoints. Or, more precisely,
can be written in the symmetrical form where
? To derive these critical values, we must consider that
It then follows that
Setting and respectively in equations () and (), one gets from () that indeed first derivatives and , and also second derivatives
If now are points, and
where i = 1, 2, ..., n are n third-degree polynomials interpolating in the interval for i = 1, ..., n such that for i = 1, ..., n−1, then the n polynomials together define a differentiable function in the interval , and
for i = 1, ..., n, where
If the sequence is such that, in addition, holds for i = 1, ..., n−1, then the resulting function will even have a continuous second derivative.
From (), (), () and () follows that this is the case if and only if
for i = 1, ..., n−1. The relations () are linear equations for the values .
For the elastic rulers being the model for the spline interpolation, one has that to the left of the left-most "knot" and to the right of the right-most "knot" the ruler can move freely and will therefore take the form of a straight line with . As should be a continuous function of , "natural splines" in addition to the linear equations () should have
i.e. that
Eventually, () together with () and () constitute linear equations that uniquely define the parameters .
There exist other end conditions, "clamped spline", which specifies the slope at the ends of the spline, and the popular "not-a-knot spline", which requires that the third derivative is also continuous at the and points. For the "not-a-knot" spline, the additional equations will read:
.
Example
are found by solving the tridiagonal linear equation system
with
For the three points
one gets that
and from () and () that
given by () is displayed.
See also
References
Further reading
External links
Cubic Spline Interpolation Online Calculation and Visualization Tool (with JavaScript source code)
Information about spline interpolation (including code in Fortran 77)
TinySpline:Open source C-library for splines which implements cubic spline interpolation
SciPy Spline Interpolation:a Python package that implements interpolation
Cubic Interpolation:Open source C#-library for cubic spline interpolation