Spline interpolation

From testwiki
Jump to navigation Jump to search

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

Interpolation with cubic splines between eight points. Hand-drawn technical drawings for shipbuilding are a historical example of spline interpolation; drawings were constructed using flexible rulers that were bent to follow pre-defined points.

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 (xi1,yi1) 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

κ=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

{qi(xi)=qi+1(xi)=yiq'i(xi)=q'i+1(xi)q'i(xi)=q'i+1(xi)1in1.

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'n1(xn1)=q'n(xn1).[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 form Template:NumBlk where Template:NumBlk Template:NumBlk Template:NumBlk

But what are k1 and k2? To derive these critical values, we must consider that

q=dqdx=dqdtdtdx=dqdt1x2x1.

It then follows that Template:NumBlk Template:NumBlk

Setting Template:Math and Template:Math respectively in equations (Template:EquationNote) and (Template:EquationNote), one gets from (Template:EquationNote) that indeed first derivatives Template:Math and Template:Math, and also second derivatives

Template:NumBlk Template:NumBlk

If now Template:Math are Template:Math points, and

Template:NumBlk

where i = 1, 2, ..., n, and t=xxi1xixi1 are n third-degree polynomials interpolating Template:Mvar in the interval Template:Math for i = 1, ..., n such that Template:Math for i = 1, ..., n − 1, then the n polynomials together define a differentiable function in the interval Template:Math, and

Template:NumBlk Template:NumBlk for i = 1, ..., n, where Template:NumBlk Template:NumBlk Template:NumBlk

If the sequence Template:Math is such that, in addition, Template:Math holds for i = 1, ..., n − 1, then the resulting function will even have a continuous second derivative.

From (Template:EquationNote), (Template:EquationNote), (Template:EquationNote) and (Template:EquationNote) follows that this is the case if and only if

Template:NumBlk

for i = 1, ..., n − 1. The relations (Template:EquationNote) are Template:Math linear equations for the Template:Math values Template:Math.

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 Template:Math. As Template:Mvar should be a continuous function of Template:Mvar, "natural splines" in addition to the Template:Math linear equations (Template:EquationNote) should have

q'1(x0)=23(y1y0)(k1+2k0)(x1x0)(x1x0)2=0,
q'n(xn)=23(ynyn1)(2kn+kn1)(xnxn1)(xnxn1)2=0,

i.e. that Template:NumBlk Template:NumBlk

Eventually, (Template:EquationNote) together with (Template:EquationNote) and (Template:EquationNote) constitute Template:Math linear equations that uniquely define the Template:Math parameters Template:Math.

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 Template:Math and Template:Math points. For the "not-a-knot" spline, the additional equations will read:

q'1(x1)=q'2(x1)1Δx12k0+(1Δx121Δx22)k11Δx22k2=2(Δy1Δx13Δy2Δx23),
q'n1(xn1)=q'n(xn1)1Δxn12kn2+(1Δxn121Δxn2)kn11Δxn2kn=2(Δyn1Δxn13ΔynΔxn3),

where Δxi=xixi1, Δyi=yiyi1.

Example

Interpolation with cubic "natural" splines between three points

In case of three points the values for k0,k1,k2 are found by solving the tridiagonal linear equation system

[a11a120a21a22a230a32a33][k0k1k2]=[b1b2b3]

with

a11=2x1x0,
a12=1x1x0,
a21=1x1x0,
a22=2(1x1x0+1x2x1),
a23=1x2x1,
a32=1x2x1,
a33=2x2x1,
b1=3y1y0(x1x0)2,
b2=3(y1y0(x1x0)2+y2y1(x2x1)2),
b3=3y2y1(x2x1)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 (Template:EquationNote) and (Template:EquationNote) that

a1=k0(x1x0)(y1y0)=0.1875,
b1=k1(x1x0)+(y1y0)=0.3750,
a2=k1(x2x1)(y2y1)=3.3750,
b2=k2(x2x1)+(y2y1)=1.6875.

In the figure, the spline function consisting of the two cubic polynomials q1(x) and q2(x) given by (Template:EquationNote) is displayed.

See also

References

Template:Reflist

Further reading

Template:Authority control