Template:Short description Template:Distinguish
In numerical analysis, the Lagrange interpolating polynomial is the unique polynomial of lowest degree that interpolates a given set of data.
Given a data set of coordinate pairs <math>(x_j, y_j)</math> with <math>0 \leq j \leq k,</math> the <math>x_j</math> are called nodes and the <math>y_j</math> are called values. The Lagrange polynomial <math>L(x)</math> has degree <math display=inline>\leq k</math> and assumes each value at the corresponding node, <math>L(x_j) = y_j.</math>
Although named after Joseph-Louis Lagrange, who published it in 1795,<ref> Template:Cite book Republished in Template:Cite book Translated as Template:Cite book</ref> the method was first discovered in 1779 by Edward Waring.<ref>Template:Cite journal</ref> It is also an easy consequence of a formula published in 1783 by Leonhard Euler.<ref>Template:Cite journal</ref>
Uses of Lagrange polynomials include the Newton–Cotes method of numerical integration, Shamir's secret sharing scheme in cryptography, and Reed–Solomon error correction in coding theory.
For equispaced nodes, Lagrange interpolation is susceptible to Runge's phenomenon of large oscillation.
DefinitionEdit
Given a set of <math display=inline>k + 1</math> nodes <math>\{x_0, x_1, \ldots, x_k\}</math>, which must all be distinct, <math>x_j \neq x_m</math> for indices <math>j \neq m</math>, the Lagrange basis for polynomials of degree <math display=inline>\leq k</math> for those nodes is the set of polynomials <math display=inline>\{\ell_0(x), \ell_1(x), \ldots, \ell_k(x)\}</math> each of degree <math display=inline>k</math> which take values <math display=inline>\ell_j(x_m) = 0</math> if <math display=inline>m \neq j</math> and <math display=inline>\ell_j(x_j) = 1</math>. Using the Kronecker delta this can be written <math display=inline>\ell_j(x_m) = \delta_{jm}.</math> Each basis polynomial can be explicitly described by the product:
<math display=block>\begin{aligned} \ell_j(x) &= \frac{(x-x_0)}{(x_j-x_0)} \cdots \frac{(x-x_{j-1})}{(x_j-x_{j - 1})} \frac{(x-x_{j+1})}{(x_j-x_{j+1})} \cdots \frac{(x-x_k)}{(x_j-x_k)} \\[8mu] &= \prod_{\begin{smallmatrix}0\le m\le k\\ m\neq j\end{smallmatrix}} \frac{x-x_m}{x_j-x_m} \vphantom\Bigg|. \end{aligned}</math>
Notice that the numerator <math display=inline>\prod_{m \neq j}(x - x_m)</math> has <math display=inline>k</math> roots at the nodes <math display=inline>\{x_m\}_{m \neq j}</math> while the denominator <math display=inline>\prod_{m \neq j}(x_j - x_m)</math> scales the resulting polynomial so that <math display=inline>\ell_j(x_j) = 1.</math>
The Lagrange interpolating polynomial for those nodes through the corresponding values <math>\{y_0, y_1, \ldots, y_k\}</math> is the linear combination:
<math display=block>L(x) = \sum_{j=0}^{k} y_j \ell_j(x).</math>
Each basis polynomial has degree <math display=inline>k</math>, so the sum <math display=inline>L(x)</math> has degree <math display=inline>\leq k</math>, and it interpolates the data because <math display=inline>L(x_m) = \sum_{j=0}^{k} y_j \ell_j(x_m) = \sum_{j=0}^{k} y_j \delta_{mj} = y_m.</math>
The interpolating polynomial is unique. Proof: assume the polynomial <math display=inline>M(x)</math> of degree <math display=inline>\leq k</math> interpolates the data. Then the difference <math display=inline>M(x) - L(x)</math> is zero at <math display=inline>k + 1</math> distinct nodes <math display=inline>\{x_0, x_1, \ldots, x_k\}.</math> But the only polynomial of degree <math display=inline>\leq k</math> with more than <math display=inline>k</math> roots is the constant zero function, so <math display=inline>M(x) - L(x) = 0,</math> or <math display=inline>M(x) = L(x).</math>
Barycentric formEdit
Each Lagrange basis polynomial <math display=inline>\ell_j(x)</math> can be rewritten as the product of three parts, a function <math display=inline>\ell(x) = \prod_m (x - x_m)</math> common to every basis polynomial, a node-specific constant <math display=inline>w_j = \prod_{m\neq j}(x_j - x_m)^{-1}</math> (called the barycentric weight), and a part representing the displacement from <math display=inline>x_j</math> to <math display=inline>x</math>:<ref>Template:Cite journal</ref>
<math display=block>\ell_j(x) = \ell(x) \dfrac{w_j}{x - x_j}</math>
By factoring <math display=inline>\ell(x)</math> out from the sum, we can write the Lagrange polynomial in the so-called first barycentric form:
- <math>L(x) = \ell(x) \sum_{j=0}^k \frac{w_j}{x-x_j}y_j.</math>
If the weights <math>w_j</math> have been pre-computed, this requires only <math>\mathcal O(k)</math> operations compared to <math>\mathcal O(k^2)</math> for evaluating each Lagrange basis polynomial <math>\ell_j(x)</math> individually.
The barycentric interpolation formula can also easily be updated to incorporate a new node <math>x_{k+1}</math> by dividing each of the <math>w_j</math>, <math>j=0 \dots k</math> by <math>(x_j - x_{k+1})</math> and constructing the new <math>w_{k+1}</math> as above.
For any <math display=inline>x,</math> <math display=inline>\sum_{j=0}^k \ell_j(x) = 1</math> because the constant function <math display=inline>g(x) = 1</math> is the unique polynomial of degree <math>\leq k</math> interpolating the data <math display=inline>\{(x_0, 1), (x_1, 1), \ldots, (x_k, 1) \}.</math> We can thus further simplify the barycentric formula by dividing <math>L(x) = L(x) / g(x)\colon</math>
- <math>\begin{aligned}
L(x) &= \ell(x) \sum_{j=0}^k \frac{w_j}{x-x_j}y_j \Bigg/ \ell(x) \sum_{j=0}^k \frac{w_j}{x-x_j} \\[10mu] &= \sum_{j=0}^k \frac{w_j}{x-x_j}y_j \Bigg/ \sum_{j=0}^k \frac{w_j}{x-x_j}. \end{aligned}</math>
This is called the second form or true form of the barycentric interpolation formula.
This second form has advantages in computation cost and accuracy: it avoids evaluation of <math>\ell(x)</math>; the work to compute each term in the denominator <math>w_j/(x-x_j)</math> has already been done in computing <math>\bigl(w_j/(x-x_j)\bigr)y_j</math> and so computing the sum in the denominator costs only <math display=inline>k</math> addition operations; for evaluation points <math display=inline>x</math> which are close to one of the nodes <math display=inline>x_j</math>, catastrophic cancelation would ordinarily be a problem for the value <math display=inline>(x-x_j)</math>, however this quantity appears in both numerator and denominator and the two cancel leaving good relative accuracy in the final result.
Using this formula to evaluate <math>L(x)</math> at one of the nodes <math>x_j</math> will result in the indeterminate <math>\infty y_j/\infty</math>; computer implementations must replace such results by <math>L(x_j) = y_j.</math>
Each Lagrange basis polynomial can also be written in barycentric form:
- <math>
\ell_j(x) = \frac{w_j}{x-x_j} \Bigg/ \sum_{m=0}^k \frac{w_m}{x-x_m}. </math>
A perspective from linear algebraEdit
Solving an interpolation problem leads to a problem in linear algebra amounting to inversion of a matrix. Using a standard monomial basis for our interpolation polynomial <math display="inline">L(x) = \sum_{j=0}^k x^j m_j</math>, we must invert the Vandermonde matrix <math>(x_i)^j</math> to solve <math>L(x_i) = y_i</math> for the coefficients <math>m_j</math> of <math>L(x)</math>. By choosing a better basis, the Lagrange basis, <math display="inline">L(x) = \sum_{j=0}^k l_j(x) y_j</math>, we merely get the identity matrix, <math>\delta_{ij}</math>, which is its own inverse: the Lagrange basis automatically inverts the analog of the Vandermonde matrix.
This construction is analogous to the Chinese remainder theorem. Instead of checking for remainders of integers modulo prime numbers, we are checking for remainders of polynomials when divided by linears.
Furthermore, when the order is large, Fast Fourier transformation can be used to solve for the coefficients of the interpolated polynomial.
ExampleEdit
We wish to interpolate <math>f(x) = x^2</math> over the domain <math>1 \leq x \leq 3</math> at the three nodes Template:Nobr
- <math>
\begin{align} x_0 & = 1, & & & y_0 = f(x_0) & = 1, \\[3mu] x_1 & = 2, & & & y_1 = f(x_1) & = 4, \\[3mu] x_2 & = 3, & & & y_2 = f(x_2) & =9. \end{align} </math>
The node polynomial <math>\ell</math> is
- <math>\ell(x) = (x-1)(x-2)(x-3) = x^3 - 6x^2 + 11x - 6.</math>
The barycentric weights are
- <math>\begin{align}
w_0 &= (1-2)^{-1}(1-3)^{-1} = \tfrac12, \\[3mu] w_1 &= (2-1)^{-1}(2-3)^{-1} = -1, \\[3mu] w_2 &= (3-1)^{-1}(3-2)^{-1} = \tfrac12. \end{align}</math>
The Lagrange basis polynomials are
- <math>\begin{align}
\ell_0(x) &= \frac{x - 2}{1 - 2}\cdot\frac{x - 3}{1 - 3} = \tfrac12x^2 - \tfrac52x + 3, \\[5mu] \ell_1(x) &= \frac{x - 1}{2 - 1}\cdot\frac{x - 3}{2 - 3} = -x^2 + 4x - 3, \\[5mu] \ell_2(x) &= \frac{x - 1}{3 - 1}\cdot\frac{x - 2}{3 - 2} = \tfrac12x^2 - \tfrac32x + 1. \end{align}</math>
The Lagrange interpolating polynomial is:
- <math> \begin{align}
L(x) &= y_0 \cdot\ell_0(x) + y_1\cdot\ell_1(x) + y_2\cdot\ell_2(x) = x^2. \end{align} </math>
In (second) barycentric form,
- <math>
L(x) = \frac
{\displaystyle \sum_{j=0}^2 \frac{w_j}{x-x_j}y_j} {\displaystyle \sum_{j=0}^2 \frac{w_j}{x-x_j}} = \frac {\displaystyle \frac{\tfrac12}{x - 1} + \frac{-4}{x - 2} + \frac{\tfrac92}{x - 3}} {\displaystyle \frac{\tfrac12}{x - 1} + \frac{-1}{x - 2} + \frac{\tfrac12}{x - 3}}.
</math>
NotesEdit
The Lagrange form of the interpolation polynomial shows the linear character of polynomial interpolation and the uniqueness of the interpolation polynomial. Therefore, it is preferred in proofs and theoretical arguments. Uniqueness can also be seen from the invertibility of the Vandermonde matrix, due to the non-vanishing of the Vandermonde determinant.
But, as can be seen from the construction, each time a node xk changes, all Lagrange basis polynomials have to be recalculated. A better form of the interpolation polynomial for practical (or computational) purposes is the barycentric form of the Lagrange interpolation (see below) or Newton polynomials.
Lagrange and other interpolation at equally spaced points, as in the example above, yield a polynomial oscillating above and below the true function. This behaviour tends to grow with the number of points, leading to a divergence known as Runge's phenomenon; the problem may be eliminated by choosing interpolation points at Chebyshev nodes.<ref>Template:Cite book.</ref>
The Lagrange basis polynomials can be used in numerical integration to derive the Newton–Cotes formulas.
Remainder in Lagrange interpolation formulaEdit
When interpolating a given function f by a polynomial of degree Template:Mvar at the nodes <math>x_0,...,x_k</math> we get the remainder <math>R(x) = f(x) - L(x)</math> which can be expressed as<ref>Template:AS ref</ref>
- <math> R(x) = f[x_0,\ldots,x_k,x] \ell(x) = \ell(x) \frac{f^{(k+1)}(\xi)}{(k+1)!}, \quad \quad x_0 < \xi < x_k,</math>
where <math>f[x_0,\ldots,x_k,x]</math> is the notation for divided differences. Alternatively, the remainder can be expressed as a contour integral in complex domain as
- <math>R(x) = \frac{\ell(x)}{2\pi i} \int_C \frac{f(t)}{(t-x)(t-x_0) \cdots (t-x_k)} dt = \frac{\ell(x)}{2\pi i} \int_C \frac{f(t)}{(t-x)\ell(t)} dt.</math>
The remainder can be bound as
- <math>|R(x)| \leq \frac{(x_k-x_0)^{k+1}}{(k+1)!}\max_{x_0 \leq \xi \leq x_k} |f^{(k+1)}(\xi)|. </math>
DerivationEdit
Clearly, <math>R(x) </math> is zero at nodes. To find <math>R(x)</math> at a point <math>x_p </math>, define a new function <math>F(x)=R(x)-\tilde{R}(x)=f(x)-L(x)-\tilde{R}(x)</math> and choose <math display="inline">\tilde{R}(x)=C\cdot\prod_{i=0}^k(x-x_i)</math> where <math>C</math> is the constant we are required to determine for a given <math>x_p</math>. We choose <math>C</math> so that <math>F(x)</math> has <math>k+2</math> zeroes (at all nodes and <math>x_p</math>) between <math>x_0</math> and <math>x_k</math> (including endpoints). Assuming that <math>f(x)</math> is <math>k+1</math>-times differentiable, since <math>L(x)</math> and <math>\tilde{R}(x)</math> are polynomials, and therefore, are infinitely differentiable, <math>F(x)</math> will be <math>k+1</math>-times differentiable. By Rolle's theorem, <math>F^{(1)}(x)</math> has <math>k+1</math> zeroes, <math>F^{(2)}(x)</math> has <math>k</math> zeroes... <math>F^{(k+1)}</math> has 1 zero, say <math>\xi,\, x_0<\xi<x_k</math>. Explicitly writing <math>F^{(k+1)}(\xi)</math>:
- <math>F^{(k+1)}(\xi)=f^{(k+1)}(\xi)-L^{(k+1)}(\xi)-\tilde{R}^{(k+1)}(\xi)</math>
- <math>L^{(k+1)}=0,\tilde{R}^{(k+1)}=C\cdot(k+1)!</math> (Because the highest power of <math>x</math> in <math>\tilde{R}(x)</math> is <math>k+1</math>)
- <math>0=f^{(k+1)}(\xi)-C\cdot(k+1)!</math>
The equation can be rearranged as<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>
- <math>C=\frac{f^{(k+1)}(\xi)}{(k+1)!}</math>
Since <math>F(x_p) = 0</math> we have <math>R(x_p)=\tilde{R}(x_p) = \frac{f^{k+1}(\xi)}{(k+1)!}\prod_{i=0}^k(x_p-x_i)</math>
DerivativesEdit
The Template:Mvarth derivative of a Lagrange interpolating polynomial can be written in terms of the derivatives of the basis polynomials,
- <math>L^{(d)}(x) := \sum_{j=0}^{k} y_j \ell_j^{(d)}(x).</math>
Recall (see Template:Slink above) that each Lagrange basis polynomial is
<math display=block>\begin{aligned} \ell_j(x) &= \prod_{\begin{smallmatrix}m = 0\\ m\neq j\end{smallmatrix}}^k \frac{x-x_m}{x_j-x_m}. \end{aligned}</math>
The first derivative can be found using the product rule:
- <math>\begin{align}
\ell_j'(x) &= \sum_{\begin{smallmatrix}i=0 \\ i\not=j\end{smallmatrix}}^k \Biggl[ \frac{1}{x_j-x_i}\prod_{\begin{smallmatrix}m=0 \\ m\not = (i , j)\end{smallmatrix}}^k \frac{x-x_m}{x_j-x_m} \Biggr] \\[5mu] &= \ell_j(x)\sum_{\begin{smallmatrix}i=0 \\i\not=j\end{smallmatrix}}^k \frac{1}{x-x_i}. \end{align}</math>
The second derivative is
- <math>\begin{align}
\ell_j(x) &= \sum_{\begin{smallmatrix}i=0 \\ i\ne j\end{smallmatrix}}^{k} \frac{1}{x_j-x_i} \Biggl[ \sum_{\begin{smallmatrix}m=0 \\ m\ne(i,j)\end{smallmatrix}}^{k} \Biggl( \frac{1}{x_j-x_m}\prod_{\begin{smallmatrix}n=0 \\ n\ne(i,j,m)\end{smallmatrix}}^{k} \frac{x-x_n}{x_j-x_n} \Biggr) \Biggr] \\[10mu] &= \ell_j(x) \sum_{0 \leq i < m \leq k} \frac{2}{(x-x_i)(x - x_m)} \\[10mu] &= \ell_j(x)\Biggl[\Biggl(\sum_{\begin{smallmatrix}i=0 \\i\not=j\end{smallmatrix}}^k \frac{1}{x-x_i}\Biggr)^2-\sum_{\begin{smallmatrix}i=0 \\i\not=j\end{smallmatrix}}^k \frac{1}{(x-x_i)^2}\Biggr]. \end{align}</math>
The third derivative is
- <math>\begin{align}
\ell_j(x) &= \ell_j(x) \sum_{0 \leq i < m < n \leq k} \frac{3!}{(x-x_i)(x - x_m)(x - x_n)} \end{align}</math>
and likewise for higher derivatives.
Note that all of these formulas for derivatives are invalid at or near a node. A method of evaluating all orders of derivatives of a Lagrange polynomial efficiently at all points of the domain, including the nodes, is converting the Lagrange polynomial to power basis form and then evaluating the derivatives.
Finite fieldsEdit
The Lagrange polynomial can also be computed in finite fields. This has applications in cryptography, such as in Shamir's Secret Sharing scheme.
See alsoEdit
- Neville's algorithm
- Newton form of the interpolation polynomial
- Bernstein polynomial
- Carlson's theorem
- Lebesgue constant
- The Chebfun system
- Table of Newtonian series
- Frobenius covariant
- Sylvester's formula
- Finite difference coefficient
- Hermite interpolation
ReferencesEdit
External linksEdit
- Template:Springer
- ALGLIB has an implementations in C++ / C# / VBA / Pascal.
- GSL has a polynomial interpolation code in C
- SO has a MATLAB example that demonstrates the algorithm and recreates the first image in this article
- Lagrange Method of Interpolation — Notes, PPT, Mathcad, Mathematica, MATLAB, Maple
- Lagrange interpolation polynomial on www.math-linux.com
- {{#invoke:Template wrapper|{{#if:|list|wrap}}|_template=cite web
|_exclude=urlname, _debug, id |url = https://mathworld.wolfram.com/{{#if:LagrangeInterpolatingPolynomial%7CLagrangeInterpolatingPolynomial.html}} |title = Lagrange Interpolating Polynomial |author = Weisstein, Eric W. |website = MathWorld |access-date = |ref = Template:SfnRef }}