spline interpolation
{{short description|Mathematical method}}
{{broader|Spline (mathematics)}}
{{more footnotes|date=July 2021}}
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.{{cite journal |last1=Hall |first1=Charles A. |last2=Meyer |first2=Weston W. |title=Optimal Error Bounds for Cubic Spline Interpolation |journal=Journal of Approximation Theory |date=1976 |volume=16 |issue=2 |pages=105–122 |doi=10.1016/0021-9045(76)90040-X |doi-access=free}} 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
:
q_i(x_i) = q_{i+1}(x_i) = y_i \\
q'_i(x_i) = q'_{i+1}(x_i) \\
q_i(x_i) = q_{i+1}(x_i)
\end{cases}
\qquad
1 \le i \le n - 1.
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 .{{Cite book |last=Burden |first=Richard |title=Numerical Analysis |last2=Faires |first2=Douglas |publisher=Cengage Learning |year=2015 |isbn=9781305253667 |edition=10th |pages=142–157}}
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
{{NumBlk|:||{{EquationRef|1}}}}
where
{{NumBlk|:||{{EquationRef|2}}}}
{{NumBlk|:||{{EquationRef|3}}}}
{{NumBlk|:||{{EquationRef|4}}}}
But what are and ? To derive these critical values, we must consider that
:
It then follows that
{{NumBlk|:||{{EquationRef|5}}}}
{{NumBlk|:||{{EquationRef|6}}}}
Setting {{math|t {{=}} 0}} and {{math|t {{=}} 1}} respectively in equations ({{EquationNote|5}}) and ({{EquationNote|6}}), one gets from ({{EquationNote|2}}) that indeed first derivatives {{math|q′(x1) {{=}} k1}} and {{math|q′(x2) {{=}} k2}}, and also second derivatives
{{NumBlk|:||{{EquationRef|7}}}}
{{NumBlk|:||{{EquationRef|8}}}}
If now {{math|(xi, yi), i {{=}} 0, 1, ..., n}} are {{math|n + 1}} points, and
{{NumBlk|:||{{EquationRef|9}}}}
where i = 1, 2, ..., n, and are n third-degree polynomials interpolating {{mvar|y}} in the interval {{math|xi−1 ≤ x ≤ xi}} for i = 1, ..., n such that {{math|q′i (xi) {{=}} q′i+1(xi)}} for i = 1, ..., n − 1, then the n polynomials together define a differentiable function in the interval {{math|x0 ≤ x ≤ xn}}, and
{{NumBlk|:||{{EquationRef|10}}}}
{{NumBlk|:||{{EquationRef|11}}}}
for i = 1, ..., n, where
{{NumBlk|:||{{EquationRef|12}}}}
{{NumBlk|:||{{EquationRef|13}}}}
{{NumBlk|:||{{EquationRef|14}}}}
If the sequence {{math|k0, k1, ..., kn}} is such that, in addition, {{math|q′′i(xi) {{=}} q′′i+1(xi)}} holds for i = 1, ..., n − 1, then the resulting function will even have a continuous second derivative.
From ({{EquationNote|7}}), ({{EquationNote|8}}), ({{EquationNote|10}}) and ({{EquationNote|11}}) follows that this is the case if and only if
{{NumBlk|:||{{EquationRef|15}}}}
for i = 1, ..., n − 1. The relations ({{EquationNote|15}}) are {{math|n − 1}} linear equations for the {{math|n + 1}} values {{math|k0, k1, ..., kn}}.
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 {{math|q′′ {{=}} 0}}. As {{mvar|q′′}} should be a continuous function of {{mvar|x}}, "natural splines" in addition to the {{math|n − 1}} linear equations ({{EquationNote|15}}) should have
:
:
i.e. that
{{NumBlk|:||{{EquationRef|16}}}}
{{NumBlk|:||{{EquationRef|17}}}}
Eventually, ({{EquationNote|15}}) together with ({{EquationNote|16}}) and ({{EquationNote|17}}) constitute {{math|n + 1}} linear equations that uniquely define the {{math|n + 1}} parameters {{math|k0, k1, ..., kn}}.
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 {{math|x1}} and {{math|xn−1}} points.
For the "not-a-knot" spline, the additional equations will read:
:
:
where .
Example
Image:Cubic splines three points.svg
In case of three points the values for are found by solving the tridiagonal linear equation system
:
\begin{bmatrix}
a_{11} & a_{12} & 0 \\
a_{21} & a_{22} & a_{23} \\
0 & a_{32} & a_{33} \\
\end{bmatrix}
\begin{bmatrix}
k_0 \\
k_1 \\
k_2 \\
\end{bmatrix}
=
\begin{bmatrix}
b_1 \\
b_2 \\
b_3 \\
\end{bmatrix}
with
:
:
:
:
:
:
:
:
:
:
For the three points
:
one gets that
:
and from ({{EquationNote|10}}) and ({{EquationNote|11}}) that
:
:
:
:
In the figure, the spline function consisting of the two cubic polynomials and given by ({{EquationNote|9}}) is displayed.
See also
References
{{Reflist}}
Further reading
- {{cite journal |last=Schoenberg |first=Isaac J. |title=Contributions to the Problem of Approximation of Equidistant Data by Analytic Functions:Part A.—On the Problem of Smoothing or Graduation. A First Class of Analytic Approximation Formulae |journal=Quarterly of Applied Mathematics |volume=4 |issue=2 |pages=45–99 |year=1946 |doi=10.1090/qam/15914 |doi-access=free }}
- {{cite journal |last=Schoenberg |first=Isaac J. |title=Contributions to the Problem of Approximation of Equidistant Data by Analytic Functions:Part B.—On the Problem of Osculatory Interpolation. A Second Class of Analytic Approximation Formulae |journal=Quarterly of Applied Mathematics |volume=4 |issue=2 |pages=112–141 |year=1946 |doi=10.1090/qam/16705 |doi-access=free }}
External links
- [http://tools.timodenk.com/?p=cubic-spline-interpolation Cubic Spline Interpolation Online Calculation and Visualization Tool (with JavaScript source code)]
- {{springer|title=Spline interpolation|id=p/s086820}}
- [http://jsxgraph.uni-bayreuth.de/wiki/index.php/Cubic_spline_interpolation Dynamic cubic splines with JSXGraph]
- [https://www.youtube.com/view_play_list?p=DAB608CD1A9A0D55 Lectures on the theory and practice of spline interpolation]
- [https://web.archive.org/web/20090408054627/http://online.redwoods.cc.ca.us/instruct/darnold/laproj/Fall98/SkyMeg/Proj.PDF Paper which explains step by step how cubic spline interpolation is done, but only for equidistant knots.]
- [http://apps.nrbook.com/c/index.html Numerical Recipes in C, Go to Chapter 3 Section 3-3]
- [http://www.cs.tau.ac.il/~turkel/notes/numeng/spline_note.pdf A note on cubic splines]
- [https://websites.pmc.ucsc.edu/~fnimmo/eart290c_17/NumericalRecipesinF77.pdf Information about spline interpolation (including code in Fortran 77)]
- [https://github.com/msteinbeck/tinyspline TinySpline:Open source C-library for splines which implements cubic spline interpolation]
- [https://docs.scipy.org/doc/scipy/tutorial/interpolate.html SciPy Spline Interpolation:a Python package that implements interpolation]
- [https://github.com/ValexCorp/Cubic-Interpolation Cubic Interpolation:Open source C#-library for cubic spline interpolation]
{{authority control}}