Spline interpolation
Template:Short description Template:Broader Template:More footnotes 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,Script error: No such module "Unsubst". 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.[1] 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.
We wish to model similar kinds of curves using a set of mathematical equations. Assume we have a sequence of knots, through . There will be a cubic polynomial between each successive pair of knots and connecting to both of them, where . So there will be polynomials, with the first polynomial starting at , and the last polynomial ending at .
The curvature of any curve is defined as
where and are the first and second derivatives of with respect to . To make the spline take a shape that minimizes the bending (under the constraint of passing through all knots), we will define both and 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 has the condition that .
In addition to the three main conditions above, a clamped cubic spline has the conditions that and where is the derivative of the interpolated function.
In addition to the three main conditions above, a not-a-knot spline has the conditions that and .[2]
Algorithm to find the interpolating cubic spline
We wish to find each polynomial given the points through . To do this, we will consider just a single piece of the curve, , which will interpolate from to . This piece will have slopes and at its endpoints. Or, more precisely,
The full equation can be written in the symmetrical form Template:NumBlk where Template:NumBlk Template:NumBlk Template:NumBlk
But what are and ? To derive these critical values, we must consider that
It then follows that Template:NumBlk Template:NumBlk
Setting t = 0Script error: No such module "Check for unknown parameters". and t = 1Script error: No such module "Check for unknown parameters". respectively in equations (5) and (6), one gets from (2) that indeed first derivatives q′(x1) = k1Script error: No such module "Check for unknown parameters". and q′(x2) = k2Script error: No such module "Check for unknown parameters"., and also second derivatives
Template:NumBlk Template:NumBlk
If now (xi, yi), i = 0, 1, ..., nScript error: No such module "Check for unknown parameters". are n + 1Script error: No such module "Check for unknown parameters". points, and
where i = 1, 2, ..., n, and are n third-degree polynomials interpolating Template:Mvar in the interval xi−1 ≤ x ≤ xiScript error: No such module "Check for unknown parameters". for i = 1, ..., n such that q′i (xi) = q′i+1(xi)Script error: No such module "Check for unknown parameters". for i = 1, ..., n − 1, then the n polynomials together define a differentiable function in the interval x0 ≤ x ≤ xnScript error: No such module "Check for unknown parameters"., and
Template:NumBlk Template:NumBlk for i = 1, ..., n, where Template:NumBlk Template:NumBlk Template:NumBlk
If the sequence k0, k1, ..., knScript error: No such module "Check for unknown parameters". is such that, in addition, q′′i(xi) = q′′i+1(xi)Script error: No such module "Check for unknown parameters". holds for i = 1, ..., n − 1, then the resulting function will even have a continuous second derivative.
From (7), (8), (10) and (11) follows that this is the case if and only if
for i = 1, ..., n − 1. The relations (15) are n − 1Script error: No such module "Check for unknown parameters". linear equations for the n + 1Script error: No such module "Check for unknown parameters". values k0, k1, ..., knScript error: No such module "Check for unknown parameters"..
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 q′′ = 0Script error: No such module "Check for unknown parameters".. As Template:Mvar should be a continuous function of Template:Mvar, "natural splines" in addition to the n − 1Script error: No such module "Check for unknown parameters". linear equations (15) should have
i.e. that Template:NumBlk Template:NumBlk
Eventually, (15) together with (16) and (17) constitute n + 1Script error: No such module "Check for unknown parameters". linear equations that uniquely define the n + 1Script error: No such module "Check for unknown parameters". parameters k0, k1, ..., knScript error: No such module "Check for unknown 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 x1Script error: No such module "Check for unknown parameters". and xn−1Script error: No such module "Check for unknown parameters". points. For the "not-a-knot" spline, the additional equations will read:
where .
Example
In case of three points the values for are found by solving the tridiagonal linear equation system
with
For the three points
one gets that
In the figure, the spline function consisting of the two cubic polynomials and given by (9) is displayed.
See also
- Akima spline
- Circular interpolation
- Cubic Hermite spline
- Centripetal Catmull–Rom spline
- Discrete spline interpolation
- Monotone cubic interpolation
- Non-uniform rational B-spline
- Multivariate interpolation
- Polynomial interpolation
- Smoothing spline
- Spline wavelet
- Thin plate spline
- Polyharmonic spline
References
<templatestyles src="Reflist/styles.css" />
Script error: No such module "Check for unknown parameters".
Further reading
- Script error: No such module "Citation/CS1".
- Script error: No such module "Citation/CS1".
External links
- Cubic Spline Interpolation Online Calculation and Visualization Tool (with JavaScript source code)
- Template:Springer
- Dynamic cubic splines with JSXGraph
- Lectures on the theory and practice of spline interpolation
- Paper which explains step by step how cubic spline interpolation is done, but only for equidistant knots.
- Numerical Recipes in C, Go to Chapter 3 Section 3-3
- A note on cubic splines
- 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