|
|
(One intermediate revision by one other user not shown) |
Line 1: |
Line 1: |
| {{See also|Spline (mathematics)}}
| | Nice to satisfy you, my name is Numbers Held although [http://Menshealth.about.com/od/diseases/a/syphilis.htm I don't] truly like being called like that. Years in the past he moved to over the counter std test North Dakota and his family enjoys it. What I adore doing is playing baseball but I haven't produced a over the counter std test dime at home std testing with it. Bookkeeping is my profession.<br><br>[http://Www.tressugar.com/How-Common-STDs-America-7492582 Feel free] to surf to my page over the counter std test ([https://pinkmulesl.zendesk.com/entries/30417152-Valuable-Guidance-For-Successfully-Treating-Candidiasis click through the next web site]) |
| In the [[mathematics|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 (mathematics)|spline]]. Spline interpolation is preferred over [[polynomial interpolation]] because the [[interpolation error]] can be made small even when using low degree polynomials for the spline. Spline interpolation avoids the problem of [[Runge's phenomenon]], which occurs when interpolating using high degree polynomials.
| |
| | |
| ==Introduction==
| |
| Originally, ''[[Flat spline|spline]]'' was a term for [[elastic]] [[ruler]]s that were bent to pass through a number of predefined points ("knots"). These were used to make [[technical drawing]]s for [[shipbuilding]] and construction by hand, as illustrated by Figure 1.
| |
| [[Image:Cubic spline.svg|thumb|upright=1.8|right|Figure 1: Interpolation with cubic splines between eight points. Hand-drawn technical drawings were made for shipbuilding etc. using flexible rulers that were bent to follow pre-defined points]]
| |
| | |
| The approach to mathematically model the shape of such elastic rulers fixed by ''n''+1 knots <math>(x_i,y_i)\quad i=0,1,\dotsc,n</math> is to interpolate between all the pairs of knots <math>(x_{i-1}\ ,\ y_{i-1})</math> and <math>(x_i\ ,\ y_i)</math> with polynomials <math>y=q_i(x), \quad i=1,2,\dotsc,n</math>.
| |
| | |
| The [[curvature]] of a curve
| |
| :<math>y=f(x)</math>
| |
| is
| |
| :<math>\kappa= \frac{y''}{(1+y'^2)^{3/2}}</math>
| |
| As the spline will take a shape that minimizes the bending (under the constraint of passing through all knots) both <math>y'</math> and <math>y''</math> will be continuous everywhere and at the knots. To achieve this one must have that
| |
| | |
| :<math>q'_i(x_i) = q'_{i+1}(x_i)</math>
| |
| | |
| and that
| |
| | |
| :<math>q''_i(x_i) = q''_{i+1}(x_i)</math>
| |
| | |
| for all ''i'', <math>1 \le i \le n-1</math>. This can only be achieved if polynomials of degree 3 or higher are used. The classical approach is to use polynomials of degree 3 — the case of [[cubic spline]]s.
| |
| | |
| ==Algorithm to find the interpolating cubic spline==
| |
| | |
| A third order polynomial <math>q(x)</math> for which
| |
| :<math>q(x_1)=y_1</math>
| |
| :<math>q(x_2)=y_2</math>
| |
| :<math>q'(x_1)=k_1</math>
| |
| :<math>q'(x_2)=k_2</math>
| |
| | |
| can be written in the symmetrical form
| |
| # {{NumBlk|:|<math>q\ =\ (1-t)\ y_1 +\ t\ y_2\ +\ t\ (1-t)\ (a\ (1-t) + b\ t)</math>|{{EquationRef|1}}}}
| |
| where {{NumBlk|:|<math>t=\tfrac{x-x_1}{x_2-x_1}</math>|{{EquationRef|2}}}} and
| |
| # {{NumBlk|:|<math>a= \ k_1 (x_2 - x_1)-(y_2 - y_1),</math>|{{EquationRef|3}}}}
| |
| # {{NumBlk|:|<math>b=-k_2 (x_2 - x_1)+(y_2 - y_1).</math>|{{EquationRef|4}}}}
| |
| | |
| As <math>q'= \tfrac{d q}{d x} = \tfrac{d q}{d t} \ \tfrac{d t}{d x} = \tfrac{d q}{d t} \ \tfrac{1}{x_2-x_1}</math> one gets that:
| |
| # {{NumBlk|:|<math>q'\ =\frac {y_2-y_1}{x_2-x_1} +(1-2t)\ \frac {a\ (1-t) + b\ t}{x_2-x_1}\ +\ \ t\ (1-t)\ \frac {b-a}{x_2-x_1},</math>|{{EquationRef|5}}}}
| |
| # {{NumBlk|:|<math>q''=2\frac {b-2a+(a-b)3t}{{(x_2-x_1)}^2}.</math>|{{EquationRef|6}}}}
| |
| | |
| Setting {{math|<var>x</var> {{=}} <var>x</var><sub>1</sub>}} and {{math|<var>x</var> {{=}} <var>x</var><sub>2</sub>}} respectively in equations ({{EquationNote|5}}) and ({{EquationNote|6}}) one gets from ({{EquationNote|2}}) that indeed first derivatives {{math|<var>q'</var>(<var>x</var><sub>1</sub>) {{=}} <var>k</var><sub>1</sub>}} and {{math|<var>q'</var>(<var>x</var><sub>2</sub>) {{=}} <var>k</var><sub>2</sub>}} and also second derivatives
| |
| # {{NumBlk|:|<math>q''(x_1)=2\frac {b-2a}{{(x_2-x_1)}^2}</math>|{{EquationRef|7}}}}
| |
| # {{NumBlk|:|<math>q''(x_2)=2\frac {a-2b}{{(x_2-x_1)}^2}</math>|{{EquationRef|8}}}}
| |
| | |
| If now {{math|(<var>x<sub>i</sub></var>, <var>y<sub>i</sub></var>)}} where {{math|<var>i</var>}} = 0, 1, ... , ''n'' are ''n''+1 points and
| |
| # {{NumBlk|:|<math>q_i\ =\ (1-t)\ y_{i-1} +\ t\ y_i\ +\ t\ (1-t)\ (a_i\ (1-t) + b_i\ t)</math>|{{EquationRef|9}}}}
| |
| where ''i'' = 1, 2, ..., ''n'' and <math>t=\tfrac{x-x_{i-1} }{ x_{i}-x_{i-1} }</math> are ''n'' third degree polynomials interpolating {{math|<var>y</var>}} in the interval
| |
| {{math|<var>x</var> <sub>''i''-1</sub> ≤ <var>x</var> ≤ <var>x</var><sub>''i''</sub> }} for ''i'' = 1,... , ''n'' such that {{math|<var>q</var>'<sub>''i''</sub> (<var>x</var><sub>''i''</sub>) {{=}} <var>q</var>' <sub>''i''+1</sub> (<var>x</var><sub>''i''</sub>)}} for ''i'' = 1, ... , ''n''-1
| |
| then the ''n'' polynomials together define a differentiable function in the interval {{math| <var>x</var><sub>0</sub> ≤ <var>x</var> ≤ <var>x</var><sub>''n''</sub>}} and
| |
| | |
| # {{NumBlk|:|<math>a_i=k_{i-1}(x_i-x_{i-1})-(y_i - y_{i-1})</math>|{{EquationRef|10}}}}
| |
| # {{NumBlk|:|<math>b_i=-k_i(x_i-x_{i-1})+(y_i - y_{i-1})</math>|{{EquationRef|11}}}}
| |
| for ''i'' = 1, ..., ''n'' where
| |
| # {{NumBlk|:|<math>k_0=q_1'(x_0)</math>|{{EquationRef|12}}}}
| |
| # {{NumBlk|:|<math>k_i=q_i'(x_i)=q_{i+1}'(x_i) \quad i=1,\dotsc ,n-1</math>|{{EquationRef|13}}}}
| |
| # {{NumBlk|:|<math>k_n=q_n'(x_n)</math>|{{EquationRef|14}}}}
| |
| | |
| If the sequence {{math|<var>k</var><sub>0</sub>, <var>k</var><sub>1</sub>, ..., <var>k</var><sub>''n''</sub>}} is such that in addition {{math|<var>q"</var><sub>''i''</sub>(<var>x</var><sub>''i''</sub>) {{=}} <var>q"</var><sub>''i''+1</sub>(<var>x</var><sub>''i''</sub>)}} for ''i'' = 1, ..., ''n''-1 the resulting function will even have a continuous second derivative.
| |
| | |
| From ({{EquationNote|7}}), ({{EquationNote|8}}), ({{EquationNote|10}}) and ({{EquationNote|11}}) follows that this is the case if and only if
| |
| # {{NumBlk|:|<math>\frac {k_{i-1}}{x_i-x_{i-1}} + \left(\frac {1}{x_i-x_{i-1}}+ \frac {1}{{x_{i+1}-x_i}}\right)\ 2k_i+
| |
| \frac {k_{i+1}}{{x_{i+1}-x_i}} =
| |
| 3\ \left(\frac {y_i - y_{i-1}}{{(x_i-x_{i-1})}^2}+\frac {y_{i+1} - y_i}{{(x_{i+1}-x_i)}^2}\right)</math>|{{EquationRef|15}}}}
| |
| for ''i'' = 1, ..., ''n''-1. The relations ({{EquationNote|15}}) are ''n''-1 linear equations for the ''n''+1 values {{math|<var>k</var><sub>0</sub>, <var>k</var><sub>1</sub>, ..., <var>k</var><sub>''n''</sub>}}.
| |
| | |
| 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 {{math|<var>q"</var> {{=}} 0 }}. As {{math|<var>q"</var>}} should be a continuous function of {{math|<var>x</var>}} one gets that for "Natural Splines" one in addition to the ''n''-1 linear equations ({{EquationNote|15}}) should have that
| |
| :<math>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,</math> | |
| :<math>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,</math>
| |
| i.e. that
| |
| # {{NumBlk|:|<math>\frac{2}{x_1-x_0} k_0\ +\frac{1}{x_1-x_0}k_1 = 3\ \frac{y_1-y_0}{(x_1-x_0)^2},</math>|{{EquationRef|16}}}}
| |
| # {{NumBlk|:|<math>\frac{1}{x_n-x_{n-1}}k_{n-1}\ +\frac{2}{x_n-x_{n-1}}k_n = 3\ \frac{y_n-y_{n-1}}{(x_n-x_{n-1})^2}.</math>|{{EquationRef|17}}}}
| |
| | |
| Eventually, ({{EquationNote|15}}) together with ({{EquationNote|16}}) and ({{EquationNote|17}}) constitute ''n''+1 linear equations that uniquely define the ''n''+1 parameters {{math|<var>k</var><sub>0</sub>, <var>k</var><sub>1</sub>, ..., <var>k</var><sub>''n''</sub>}}.
| |
| | |
| ==Example==
| |
| | |
| [[Image:Cubic splines three points.svg|frame|right|Figure 2: Interpolation with cubic "natural" splines between three points.]]
| |
| In case of three points the values for <math>k_0,k_1,k_2</math> are found by solving the [[Tridiagonal matrix|tridiagonal linear equation system]]
| |
| :<math>
| |
| \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}
| |
| </math>
| |
| with
| |
| :<math>a_{11}=\frac{2}{x_1-x_0}</math>
| |
| :<math>a_{12}=\frac{1}{x_1-x_0}</math>
| |
| :<math>a_{21}=\frac{1}{x_1-x_0}</math>
| |
| :<math>a_{22}=2\ \left(\frac {1}{x_1-x_0}+ \frac {1}{{x_2-x_1}}\right)</math>
| |
| :<math>a_{23}=\frac {1}{{x_2-x_1}}</math>
| |
| :<math>a_{32}=\frac{1}{x_2-x_1}</math>
| |
| :<math>a_{33}=\frac{2}{x_2-x_1}</math>
| |
| :<math>b_1=3\ \frac{y_1-y_0}{(x_1-x_0)^2}</math>
| |
| :<math>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)</math>
| |
| :<math>b_3=3\ \frac{y_2-y_1}{(x_2-x_1)^2}</math>
| |
| | |
| For the three points | |
| :<math>(-1,0.5)\ ,\ (0,0)\ ,\ (3,3)</math>
| |
| one gets that
| |
| :<math>k_0=-0.6875\ ,\ k_1=-0.1250\ ,\ k_2=1.5625</math>
| |
| and from ({{EquationNote|10}}) and ({{EquationNote|11}}) that
| |
| :<math>a_1= k_0(x_1-x_0)-(y_1 - y_0)=-0.1875</math>
| |
| :<math>b_1=-k_1(x_1-x_0)+(y_1 - y_0)=-0.3750</math>
| |
| :<math>a_2= k_1(x_2-x_1)-(y_2 - y_1)=-3.3750</math>
| |
| :<math>b_2=-k_2(x_2-x_1)+(y_2 - y_1)=-1.6875</math>
| |
| | |
| In Figure 2 the spline function consisting of the two cubic polynomials <math>q_1(x)</math> and <math>q_2(x)</math> given by ({{EquationNote|9}}) is displayed
| |
| | |
| ==See also==
| |
| *[[Cubic Hermite spline]]
| |
| *[[Monotone cubic interpolation]]
| |
| *[[NURBS]]
| |
| *[[Multivariate interpolation]]
| |
| *[[Polynomial interpolation]]
| |
| * [[Smoothing spline]]
| |
| | |
| ==External links==
| |
| * {{springer|title=Spline interpolation|id=p/s086820}}
| |
| * [http://jsxgraph.uni-bayreuth.de/wiki/index.php/Cubic_spline_interpolation Dynamic cubic splines with JSXGraph]
| |
| * [http://www.youtube.com/view_play_list?p=DAB608CD1A9A0D55 Lectures on the theory and practice of spline interpolation]
| |
| * [http://web.archive.org/web/20090408054627/http://online.redwoods.cc.ca.us/instruct/darnold/laproj/Fall98/SkyMeg/Proj.PDF Paper which explains step by step how cubic spline interpolation is done, but only for equidistant knots.]
| |
| * [http://www.akiti.ca/CubicSpline.html Online Cubic Spline Interpolation Utility]
| |
| * [http://apps.nrbook.com/c/index.html Numerical Recipes in C], Go to Chapter 3 Section 3-3.
| |
| | |
| [[Category:Splines]]
| |
| [[Category:Interpolation]]
| |