Spline interpolation explained

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.

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

n+1

knots,

(x0,y0)

through

(xn,yn)

. There will be a cubic polynomial

qi(x)=y

between each successive pair of knots

(xi-1,yi-1)

and

(xi,yi)

connecting to both of them, where

i=1,2,...,n

. So there will be

n

polynomials, with the first polynomial starting at

(x0,y0)

, and the last polynomial ending at

(xn,yn)

.

The curvature of any curve

y=y(x)

is defined as

\kappa=

y''
(1+y'2)3/2

,

where

y'

and

y''

are the first and second derivatives of

y(x)

with respect to

x

.To make the spline take a shape that minimizes the bending (under the constraint of passing through all knots), we will define both

y'

and

y''

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

\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' has the condition that

q''1(x0)=q''n(xn)=0

.

In addition to the three main conditions above, a 'clamped cubic spline' has the conditions that

q'1(x0)=f'(x0)

and

q'n(xn)=f'(xn)

where

f'(x)

is the derivative of the interpolated function.

In addition to the three main conditions above, a 'not-a-knot spline' has the conditions that

q'''1(x1)=q'''2(x1)

and

q'''n-1(xn-1)=q'''n(xn-1)

.[2]

Algorithm to find the interpolating cubic spline

We wish to find each polynomial

qi(x)

given the points

(x0,y0)

through

(xn,yn)

. To do this, we will consider just a single piece of the curve,

q(x)

, which will interpolate from

(x1,y1)

to

(x2,y2)

. This piece will have slopes

k1

and

k2

at its endpoints. Or, more precisely,

q(x1)=y1,

q(x2)=y2,

q'(x1)=k1,

q'(x2)=k2.

The full equation

q(x)

can be written in the symmetrical formwhere

But what are

k1

and

k2

? To derive these critical values, we must consider that

q'=

dq
dx

=

dq
dt
dt
dx

=

dq
dt
1
x2-x1

.

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, and

t=\tfrac{x-xi-1

} 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

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,

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:

q'''1(x1)=q'''2(x1)

1
\Delta
2
x
1

k0+\left(

1
\Delta
2
x
1

-

1
\Delta
2
x
2

\right)k1-

1
\Delta
2
x
2

k2=2\left(

\Deltay1
\Delta
3
x
1

-

\Deltay2
\Delta
3
x
2

\right),

q'''n-1(xn-1)=q'''n(xn-1)

1
\Delta
2
x
n-1

kn-2+\left(

1
\Delta
2
x
n-1

-

1
\Delta
2
x
n

\right)kn-1-

1
\Delta
2
x
n

kn=2\left(

\Deltayn-1
\Delta
3
x
n-1

-

\Deltayn
\Delta
3
x
n

\right),

where

\Deltaxi=xi-xi-1,\Deltayi=yi-yi-1

.

Example

In case of three points the values for

k0,k1,k2

are found by solving the tridiagonal linear equation system

\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}

with

a11=

2
x1-x0

,

a12=

1
x1-x0

,

a21=

1
x1-x0

,

a22=2\left(

1
x1-x0

+

1
{x2-x1
}\right),

a23=

1
{x2-x1
},

a32=

1
x2-x1

,

a33=

2
x2-x1

,

b1=3

y1-y0
(x-
2
x
0)
1

,

b2=3\left(

y1-y0
{(x1-x0)

2}+

y2-y1
{(x2-x1)

2}\right),

b3=3

y2-y1
(x-
2
x
1)
2

.

For the three points

(-1,0.5),(0,0),(3,3),

one gets that

k0=-0.6875,k1=-0.1250,k2=1.5625,

and from and that

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)

and

q2(x)

given by is displayed.

See also

Further reading

External links

Notes and References

  1. Hall . Charles A. . Meyer . Weston W. . Optimal Error Bounds for Cubic Spline Interpolation . Journal of Approximation Theory . 1976 . 16 . 2 . 105–122 . 10.1016/0021-9045(76)90040-X . free.
  2. Book: Burden, Richard . Numerical Analysis . Faires . Douglas . Cengage Learning . 2015 . 9781305253667 . 10th . 142–157.