Spline interpolation

Last updated

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.

Contents

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. Cubic spline.svg
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 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

 

 

 

 

(1)

where

 

 

 

 

(2)

 

 

 

 

(3)

 

 

 

 

(4)

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

It then follows that

 

 

 

 

(5)

 

 

 

 

(6)

Setting t = 0 and t = 1 respectively in equations ( 5 ) and ( 6 ), one gets from ( 2 ) that indeed first derivatives q′(x1) = k1 and q′(x2) = k2, and also second derivatives

 

 

 

 

(7)

 

 

 

 

(8)

If now (xi, yi), i = 0, 1, ..., n are n + 1 points, and

 

 

 

 

(9)

where i = 1, 2, ..., n, and are n third-degree polynomials interpolating y in the interval xi−1xxi for i = 1, ..., n such that q′i (xi) = q′i+1(xi) for i = 1, ..., n  1, then the n polynomials together define a differentiable function in the interval x0xxn, and

 

 

 

 

(10)

 

 

 

 

(11)

for i = 1, ..., n, where

 

 

 

 

(12)

 

 

 

 

(13)

 

 

 

 

(14)

If the sequence k0, k1, ..., kn is such that, in addition, 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 ( 7 ), ( 8 ), ( 10 ) and ( 11 ) follows that this is the case if and only if

 

 

 

 

(15)

for i = 1, ..., n  1. The relations ( 15 ) are n − 1 linear equations for the n + 1 values 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 q′′ = 0. As q′′ should be a continuous function of x, "natural splines" in addition to the n − 1 linear equations ( 15 ) should have

i.e. that

 

 

 

 

(16)

 

 

 

 

(17)

Eventually, ( 15 ) together with ( 16 ) and ( 17 ) constitute n + 1 linear equations that uniquely define the n + 1 parameters 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 x1 and xn−1 points. For the "not-a-knot" spline, the additional equations will read:

where .

Example

Interpolation with cubic "natural" splines between three points Cubic splines three points.svg
Interpolation with cubic "natural" splines between three points

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

and from ( 10 ) and ( 11 ) that

In the figure, the spline function consisting of the two cubic polynomials and given by ( 9 ) is displayed.

See also

Computer code

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

Related Research Articles

<span class="mw-page-title-main">Interpolation</span> Method for estimating new data within known data points

In the mathematical field of numerical analysis, interpolation is a type of estimation, a method of constructing (finding) new data points based on the range of a discrete set of known data points.

<span class="mw-page-title-main">B-spline</span> Spline function

In the mathematical subfield of numerical analysis, a B-spline or basis spline is a spline function that has minimal support with respect to a given degree, smoothness, and domain partition. Any spline function of given degree can be expressed as a linear combination of B-splines of that degree. Cardinal B-splines have knots that are equidistant from each other. B-splines can be used for curve-fitting and numerical differentiation of experimental data.

A finite difference is a mathematical expression of the form f (x + b) − f (x + a). If a finite difference is divided by ba, one gets a difference quotient. The approximation of derivatives by finite differences plays a central role in finite difference methods for the numerical solution of differential equations, especially boundary value problems.

<span class="mw-page-title-main">Differential calculus</span> Area of mathematics; subarea of calculus

In mathematics, differential calculus is a subfield of calculus that studies the rates at which quantities change. It is one of the two traditional divisions of calculus, the other being integral calculus—the study of the area beneath a curve.

In mathematics, the discriminant of a polynomial is a quantity that depends on the coefficients and allows deducing some properties of the roots without computing them. More precisely, it is a polynomial function of the coefficients of the original polynomial. The discriminant is widely used in polynomial factoring, number theory, and algebraic geometry.

<span class="mw-page-title-main">Cubic equation</span> Polynomial equation of degree 3

In algebra, a cubic equation in one variable is an equation of the form

In numerical analysis, polynomial interpolation is the interpolation of a given bivariate data set by the polynomial of lowest possible degree that passes through the points of the dataset.

In the mathematical field of numerical analysis, a Newton polynomial, named after its inventor Isaac Newton, is an interpolation polynomial for a given set of data points. The Newton polynomial is sometimes called Newton's divided differences interpolation polynomial because the coefficients of the polynomial are calculated using Newton's divided differences method.

<span class="mw-page-title-main">Quartic function</span> Polynomial function of degree four

In algebra, a quartic function is a function of the form

In linear algebra, a Vandermonde matrix, named after Alexandre-Théophile Vandermonde, is a matrix with the terms of a geometric progression in each row: an matrix

In mathematics, an algebraic equation or polynomial equation is an equation of the form , where P is a polynomial with coefficients in some field, often the field of the rational numbers. For example, is an algebraic equation with integer coefficients and

<span class="mw-page-title-main">Spline (mathematics)</span> Mathematical function defined piecewise by polynomials

In mathematics, a spline is a function defined piecewise by polynomials. In interpolating problems, spline interpolation is often preferred to polynomial interpolation because it yields similar results, even when using low degree polynomials, while avoiding Runge's phenomenon for higher degrees.

In numerical analysis, a cubic Hermite spline or cubic Hermite interpolator is a spline where each piece is a third-degree polynomial specified in Hermite form, that is, by its values and first derivatives at the end points of the corresponding domain interval.

<span class="mw-page-title-main">Bicubic interpolation</span> Extension of cubic spline interpolation

In mathematics, bicubic interpolation is an extension of cubic spline interpolation for interpolating data points on a two-dimensional regular grid. The interpolated surface is smoother than corresponding surfaces obtained by bilinear interpolation or nearest-neighbor interpolation. Bicubic interpolation can be accomplished using either Lagrange polynomials, cubic splines, or cubic convolution algorithm.

In mathematics, differential algebra is, broadly speaking, the area of mathematics consisting in the study of differential equations and differential operators as algebraic objects in view of deriving properties of differential equations and operators without computing the solutions, similarly as polynomial algebras are used for the study of algebraic varieties, which are solution sets of systems of polynomial equations. Weyl algebras and Lie algebras may be considered as belonging to differential algebra.

In numerical analysis, finite-difference methods (FDM) are a class of numerical techniques for solving differential equations by approximating derivatives with finite differences. Both the spatial domain and time interval are discretized, or broken into a finite number of steps, and the value of the solution at these discrete points is approximated by solving algebraic equations containing finite differences and values from nearby points.

In applied mathematics, polyharmonic splines are used for function approximation and data interpolation. They are very useful for interpolating and fitting scattered data in many dimensions. Special cases include thin plate splines and natural cubic splines in one dimension.

<span class="mw-page-title-main">Polar curve</span>

In algebraic geometry, the first polar, or simply polar of an algebraic plane curve C of degree n with respect to a point Q is an algebraic curve of degree n−1 which contains every point of C whose tangent line passes through Q. It is used to investigate the relationship between the curve and its dual, for example in the derivation of the Plücker formulas.

In the mathematical field of numerical analysis, monotone cubic interpolation is a variant of cubic interpolation that preserves monotonicity of the data set being interpolated.

In applied mathematics, an Akima spline is a type of non-smoothing spline that gives good fits to curves where the second derivative is rapidly varying. The Akima spline was published by Hiroshi Akima in 1970 from Akima's pursuit of a cubic spline curve that would appear more natural and smooth, akin to an intuitively hand-drawn curve. The Akima spline has become the algorithm of choice for several computer graphics applications. Its advantage over the cubic spline curve is its stability with respect to outliers.

References

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