maths.free › Numerical Methods › Integration and interpolation › Spline interpolation
Spline interpolation
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.
Spline interpolation
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. 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, \((x_0, y_0)\) through \((x_n, y_n)\). There will be a cubic polynomial \(q_i(x)=y\) between each successive pair of knots \((x_{i-1}, y_{i-1})\) and \((x_i, y_i)\) connecting to both of them, where \(i = 1, 2, \dots, n\). So there will be \(n\) polynomials, with the first polynomial starting at \((x_0, y_0)\), and the last polynomial ending at \((x_n, y_n)\).
The curvature of any curve \(y = y(x)\) is defined as
\(\kappa = \frac{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} 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 \(q''_1(x_0) = q''_n(x_n) = 0\).
In addition to the three main conditions above, a clamped cubic spline has the conditions that \(q'_1(x_0) = f'(x_0)\) and \(q'_n(x_n) = f'(x_n)\) where \(f'(x)\) is the derivative of the interpolated function.
Condensed: the full section is in Wikipedia.
Algorithm to find the interpolating cubic spline
We wish to find each polynomial \(q_i(x)\) given the points \((x_0, y_0)\) through \((x_n, y_n)\). To do this, we will consider just a single piece of the curve, \(q(x)\), which will interpolate from \((x_1, y_1)\) to \((x_2, y_2)\). This piece will have slopes \(k_1\) and \(k_2\) at its endpoints. Or, more precisely,
\(q(x_1) = y_1,\)
\(q(x_2) = y_2,\)
\(q'(x_1) = k_1,\)
\(q'(x_2) = k_2.\)
The full equation \(q(x)\) can be written in the symmetrical form
where
But what are \(k_1\) and \(k_2\)? To derive these critical values, we must consider that
\(q' = \frac{dq}{dx} = \frac{dq}{dt} \frac{dt}{dx} = \frac{dq}{dt} \frac{1}{x_2 - x_1}.\)
It then follows that
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
If now (xi, yi), i = 0, 1, ..., n are n + 1 points, and
\(q''_1(x_0) = 2 \frac {3(y_1 - y_0) - (k_1 + 2k_0)(x_1 - x_0)}{{(x_1 - x_0)}^2} = 0,\)
\(q''_n(x_n) = -2 \frac {3(y_n - y_{n-1}) - (2k_n + k_{n-1})(x_n - x_{n-1})}{{(x_n - x_{n-1})}^2} = 0,\)
\(q'''_1(x_1) = q'''_2(x_1) \Rightarrow \frac{1}{\Delta x_1^2} k_0 + \left( \frac{1}{\Delta x_1^2} - \frac{1}{\Delta x_2^2} \right) k_1 - \frac{1}{\Delta x_2^2} k_2 = 2 \left( \frac{\Delta y_1}{\Delta x_1^3} - \frac{\Delta y_2}{\Delta x_2^3} \right),\)
\(q'''_{n-1}(x_{n-1}) = q'''_n(x_{n-1}) \Rightarrow \frac{1}{\Delta x_{n-1}^2} k_{n-2} + \left( \frac{1}{\Delta x_{n-1}^2} - \frac{1}{\Delta x_n^2} \right) k_{n-1} - \frac{1}{\Delta x_n^2} k_n = 2\left( \frac{\Delta y_{n-1} }{\Delta x_{n-1}^3 }- \frac{ \Delta y_n}{ \Delta x_n^3 } \right),\)
Condensed: the full section is in Wikipedia.
Example
In case of three points the values for \(k_0, k_1, k_2\) 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
\(a_{11} = \frac{2}{x_1 - x_0},\)
\(a_{12} = \frac{1}{x_1 - x_0},\)
\(a_{21} = \frac{1}{x_1 - x_0},\)
\(a_{22} = 2 \left(\frac{1}{x_1 - x_0} + \frac{1}{{x_2 - x_1}}\right),\)
\(a_{23} = \frac{1}{{x_2 - x_1}},\)
\(a_{32} = \frac{1}{x_2 - x_1},\)
\(a_{33} = \frac{2}{x_2 - x_1},\)
\(b_1 = 3 \frac{y_1 - y_0}{(x_1 - x_0)^2},\)
\(b_2 = 3 \left(\frac{y_1 - y_0}{{(x_1 - x_0)}^2} + \frac{y_2 - y_1}{{(x_2 - x_1)}^2}\right),\)
\(b_3 = 3 \frac{y_2 - y_1}{(x_2 - x_1)^2}.\)
For the three points
\((-1,0.5),\ (0,0),\ (3,3),\)
one gets that
\(k_0 = -0.6875,\ k_1 = -0.1250,\ k_2 = 1.5625,\)
and from (10) and (11) that
\(a_1 = k_0(x_1 - x_0) - (y_1 - y_0) = -0.1875,\)
\(b_1 = -k_1(x_1 - x_0) + (y_1 - y_0) = -0.3750,\)
\(a_2 = k_1(x_2 - x_1) - (y_2 - y_1) = -3.3750,\)
\(b_2 = -k_2(x_2 - x_1) + (y_2 - y_1) = -1.6875.\)
In the figure, the spline function consisting of the two cubic polynomials \(q_1(x)\) and \(q_2(x)\) given by (9) is displayed.
Núna ūú Engin reiknivél leysir þetta, en hlutar þess eru reiknanlegir. Prófaðu einn hér fyrir neðan, eða sláðu inn þinn eigin.
Ókeypis reikningur bætir við athugasemdum við hverja kennslustund, skrá yfir það sem þú hefur lokið, leyst vandamál á einum stað og kennari sem þú getur spurt um þessa síðu.Stærðfræðin sjálf er opin öllum, skráður inn eða ekki.
Skráðu þig inn InnskráningTákn notuð hér
Pikkaðu á hvaða tákn sem er fyrir fulla skilgreiningu, mynd og hvað hvert bréf í því merkir.
Spurningar sem fólk spyr
Why not just solve exactly?
Most equations have no closed-form solution at all, and many that do are unusable in practice. A numerical method delivers as many correct digits as you need, and a good one tells you how many that is.
Why can Newton's method fail?
If it starts where the tangent is nearly flat it shoots far away; near a repeated root it slows to a crawl; and with several roots it may land on the wrong one. A bracketing method like bisection is slower but cannot fail.
Hlutar þessarar síðu eru aðlagað frá Wikipedia (CC BY-SA 4.0). Þjappað og endurútskýrt hér; villur eru okkar.
Meira í Numerical Methods
Root finding: bisection and Newton's methodNumerical integration: trapezoid and SimpsonInterpolation and Taylor approximationFloating point and error