Lagrange polynomial
In numerical analysis, a Lagrange polynomial, named after Joseph Louis Lagrange, is the interpolating polynomial for a given set of data points in the Lagrange form. It was first discovered by Edward Waring in 1779 and later rediscovered by Leonhard Euler in 1783.
Notice that, for any given set of data points, there is only one polynomial (of least possible degree) that interpolates these points. Thus, it is more appropriate to call it "the Lagrange form of the interpolation polynomial" rather than "the Lagrange interpolation polynomial".

Definition
Given a set of k + 1 data points
where no two xj are the same, the interpolation polynomial in the Lagrange form is a linear combination
of Lagrange basis polynomials
Proof
The function we are looking for has to be a polynomial function L(x) of degree less than or equal to k with
The Lagrange polynomial is a solution to the interpolation problem.
As can be seen
- is a polynomial and has degree k.
Thus the function L(x) is a polynomial with degree at most k and
There can be only one solution to the interpolation problem since the difference of two such solutions would be a polynomial with degree at most k and k + 1 zeros. This is only possible if the difference is identically zero, so L(x) is the unique polynomial interpolating the given data.
Main idea
Solving an interpolation problem leads to a problem in linear algebra where we have to solve a matrix. Using a standard monomial basis for our interpolation polynomial we get the Vandermonde matrix. By choosing another basis, the Lagrange basis, we get the much simpler identity matrix = δi,j which we can solve instantly: the Lagrange basis inverts the Vandermonde matrix.
Implementation in C++
Note : "pos" and "val" arrays are of size "degree".
float lagrangeInterpolatingPolynomial (float pos[], float val[], int degree, float desiredPos) {
float retVal = 0;
for (int i = 0; i < degree; ++i) {
float weight = 1;
for (int j = 0; j < degree; ++j) {
// The i-th term has to be skipped
if (j != i) {
weight *= (desiredPos - pos[j]) / (pos[i] - pos[j]);
}
}
retVal += weight * val[i];
}
return retVal;
}
Usage
Example 1

Find an interpolation formula for ƒ(x) = tan(x) given this set of known values:
The basis polynomials are:
Thus the interpolating polynomial then is
Example 2
We wish to interpolate ƒ(x) = x2 over the range 1 ≤ x ≤ 3, given these three points:
The interpolating polynomial is:
Example 3
We wish to interpolate ƒ(x) = x3 over the range 1 ≤ x ≤ 3, given these 3 points:
The interpolating polynomial is:
Notes
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.
The Lagrange basis polynomials can be used in numerical integration to derive the Newton–Cotes formulas.
Barycentric interpolation
Using the quantity
we can rewrite the Lagrange basis polynomials as
or, by defining the barycentric weights[1]
we can simply write
which is commonly referred to as the first form of the barycentric interpolation formula.
The advantage of this representation is that the interpolation polynomial may now be evaluated as
which, if the weights have been pre-computed, requires only operations (evaluating and the weights ) as opposed to for evaluating the Lagrange basis polynomials individually.
The barycentric interpolation formula can also easily be updated to incorporate a new node by dividing each of the , by and constructing the new as above.
We can further simplify the first form by first considering the barycentric interpolation of the constant function :
Dividing by does not modify the interpolation, yet yields
which is referred to as the second form or true form of the barycentric interpolation formula. This second form has the advantage, that need not be evaluated for each evaluation of .
See also
- Polynomial interpolation
- Newton form of the interpolation polynomial
- Bernstein form of the interpolation polynomial
- Newton–Cotes formulas
- Lebesgue constant (interpolation)
References
- ^ Jean-Paul Berrut, Lloyd N. Trefethen (2004). "Barycentric Lagrange Interpolation". SIAM Review. 46 (3): 501–517. doi:10.1137/S0036144502417715.
External links
- ALGLIB has an implementations in C++ / C# / VBA / Pascal.
- GSL has a polynomial interpolation code in C
- Lagrange Method of Interpolation — Notes, PPT, Mathcad, Mathematica, MATLAB, Maple at Holistic Numerical Methods Institute
- Lagrange interpolation polynomial on www.math-linux.com
- Weisstein, Eric W. "Lagrange Interpolating Polynomial". MathWorld.
- Module for Lagrange Polynomials by John H. Mathews
- The chebfun Project[1] at Oxford University
- Dynamic Lagrange interpolation with JSXGraph
- ^ Zachary Battles, Lloyd N. Trefethen (2004). "An Extension of MATLAB to Continuous Functions and Operators". SIAM J. Sci. Comput. 25 (5): 1743–1770. doi:10.1137/S1064827503430126.