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.[1] Spline interpolation also avoids the problem of Runge's phenomenon, in which oscillation can occur between points when interpolating using high-degree polynomials.
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
n+1
(x0,y0)
(xn,yn)
qi(x)=y
(xi-1,yi-1)
(xi,yi)
i=1,2,...,n
n
(x0,y0)
(xn,yn)
The curvature of any curve
y=y(x)
\kappa=
y'' | |
(1+y'2)3/2 |
,
where
y'
y''
y(x)
x
y'
y''
\begin{cases} qi(xi)=qi+1(xi)=yi\\ q'i(xi)=q'i+1(xi)\\ q''i(xi)=q''i+1(xi) \end{cases} 1\lei\len-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
q''1(x0)=q''n(xn)=0
In addition to the three main conditions above, a 'clamped cubic spline
q'1(x0)=f'(x0)
q'n(xn)=f'(xn)
f'(x)
In addition to the three main conditions above, a 'not-a-knot spline
q'''1(x1)=q'''2(x1)
q'''n-1(xn-1)=q'''n(xn-1)
We wish to find each polynomial
qi(x)
(x0,y0)
(xn,yn)
q(x)
(x1,y1)
(x2,y2)
k1
k2
q(x1)=y1,
q(x2)=y2,
q'(x1)=k1,
q'(x2)=k2.
The full equation
q(x)
But what are
k1
k2
q'=
dq | |
dx |
=
dq | |
dt |
dt | |
dx |
=
dq | |
dt |
1 | |
x2-x1 |
.
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, and
t=\tfrac{x-xi-1
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
q''1(x0)=2
3(y1-y0)-(k1+2k0)(x1-x0) | |
{(x1-x0) |
2}=0,
q''n(xn)=-2
3(yn-yn-1)-(2kn+kn-1)(xn-xn-1) | |
{(xn-xn-1) |
2}=0,
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:
q'''1(x1)=q'''2(x1) ⇒
1 | ||||||||
|
k0+\left(
1 | ||||||||
|
-
1 | ||||||||
|
\right)k1-
1 | ||||||||
|
k2=2\left(
\Deltay1 | ||||||||
|
-
\Deltay2 | ||||||||
|
\right),
q'''n-1(xn-1)=q'''n(xn-1) ⇒
1 | ||||||||
|
kn-2+\left(
1 | ||||||||
|
-
1 | ||||||||
|
\right)kn-1-
1 | ||||||||
|
kn=2\left(
\Deltayn-1 | ||||||||
|
-
\Deltayn | ||||||||
|
\right),
where
\Deltaxi=xi-xi-1, \Deltayi=yi-yi-1
In case of three points the values for
k0,k1,k2
\begin{bmatrix} a11&a12&0\\ a21&a22&a23\\ 0&a32&a33\\ \end{bmatrix} \begin{bmatrix} k0\\ k1\\ k2\\ \end{bmatrix} = \begin{bmatrix} b1\\ b2\\ b3\\ \end{bmatrix}
a11=
2 | |
x1-x0 |
,
a12=
1 | |
x1-x0 |
,
a21=
1 | |
x1-x0 |
,
a22=2\left(
1 | |
x1-x0 |
+
1 | |
{x2-x1 |
a23=
1 | |
{x2-x1 |
a32=
1 | |
x2-x1 |
,
a33=
2 | |
x2-x1 |
,
b1=3
y1-y0 | ||||||||||||
|
,
b2=3\left(
y1-y0 | |
{(x1-x0) |
2}+
y2-y1 | |
{(x2-x1) |
2}\right),
b3=3
y2-y1 | ||||||||||||
|
.
For the three points
(-1,0.5), (0,0), (3,3),
k0=-0.6875, k1=-0.1250, k2=1.5625,
a1=k0(x1-x0)-(y1-y0)=-0.1875,
b1=-k1(x1-x0)+(y1-y0)=-0.3750,
a2=k1(x2-x1)-(y2-y1)=-3.3750,
b2=-k2(x2-x1)+(y2-y1)=-1.6875.
In the figure, the spline function consisting of the two cubic polynomials
q1(x)
q2(x)