Lagrange Interpolation
Lagrange interpolation finds the polynomial of lowest degree that passes exactly through a set of points. For n + 1 points with different x-values, the polynomial is P(x) = \sum_{k=0}^{n} y_k L_k(x), where each basis polynomial Lₖ(x) equals 1 at xₖ and 0 at every other node. It is used to estimate values between data points.
Before this lesson: Multiplying Polynomials and Graphing Polynomial Functions
The idea: build the curve from switches
Suppose you know a function only at a few points, called nodes: (x₀, y₀), (x₁, y₁), …, (xₙ, yₙ). Interpolation means finding a simple function, here a polynomial, that passes through all of them, so you can estimate values in between.
Lagrange’s trick is to build one small polynomial for each node that acts like a switch: Lₖ(x) is 1 at its own node xₖ and 0 at all the others. Multiply each switch by its y-value and add. At any node, every switch is off except one, so the sum gives exactly the right y-value.
To make Lₖ zero at every other node, put a factor (x − xⱼ) in the numerator for each j ≠ k. To make it equal 1 at xₖ, divide by the same product evaluated at xₖ.
Lagrange interpolation formula
L_k(x) = \prod_{j \ne k} \frac{x - x_j}{x_k - x_j}, \qquad P(x) = \sum_{k=0}^{n} y_k\,L_k(x)For three nodes x₀, x₁, x₂ the basis polynomials are
L_0(x) = \frac{(x - x_1)(x - x_2)}{(x_0 - x_1)(x_0 - x_2)}, \quad L_1(x) = \frac{(x - x_0)(x - x_2)}{(x_1 - x_0)(x_1 - x_2)}, \quad L_2(x) = \frac{(x - x_0)(x - x_1)}{(x_2 - x_0)(x_2 - x_1)}Uniqueness theorem. For n + 1 points with distinct x-values, there is exactly one polynomial of degree at most n through all of them. So Lagrange’s formula, Newton’s form and solving a linear system for the coefficients all give the same polynomial, just written differently.
- List the nodes x₀, …, xₙ and values y₀, …, yₙ. The x-values must all be different.
- Write each Lₖ(x): the product of (x − xⱼ) over j ≠ k, divided by the same product with x = xₖ.
- To estimate one value, substitute that x into each Lₖ first; the numbers are easier than the algebra.
- Add up yₖLₖ(x). Expand only if you need P(x) in standard form.
Lagrange interpolation examples
Example 1: Two points give a line
Find the Lagrange polynomial through (1, 3) and (4, 9), and use it to estimate the value at x = 2.
L_0(x) = \frac{x - 4}{1 - 4} = -\frac{x - 4}{3}Basis polynomial for x₀ = 1: zero at x = 4.
L_1(x) = \frac{x - 1}{4 - 1} = \frac{x - 1}{3}Basis polynomial for x₁ = 4: zero at x = 1.
P(x) = 3\cdot\left(-\frac{x - 4}{3}\right) + 9\cdot\frac{x - 1}{3}Multiply each basis polynomial by its y-value and add.
P(x) = -(x - 4) + 3(x - 1)
Simplify each fraction.
P(x) = -x + 4 + 3x - 3
Distribute (see distributive property).
P(x) = 2x + 1
Combine like terms (see combining like terms).
P(2) = 2(2) + 1 = 5
Substitute x = 2.
Answer: P(x) = 2x + 1 and P(2) = 5. With two points, Lagrange interpolation is just the line through them, written in a new way.
Example 2: A quadratic through three points
Find the polynomial of degree at most 2 through (0, 1), (1, 3) and (3, 13).
L_0(x) = \frac{(x - 1)(x - 3)}{(0 - 1)(0 - 3)} = \frac{x^2 - 4x + 3}{3}Multiply the binomials (see multiplying binomials); the denominator is (−1)(−3) = 3.
L_1(x) = \frac{(x - 0)(x - 3)}{(1 - 0)(1 - 3)} = \frac{x^2 - 3x}{-2}The denominator is (1)(−2) = −2.
L_2(x) = \frac{(x - 0)(x - 1)}{(3 - 0)(3 - 1)} = \frac{x^2 - x}{6}The denominator is (3)(2) = 6.
P(x) = 1\cdot\frac{x^2 - 4x + 3}{3} + 3\cdot\frac{x^2 - 3x}{-2} + 13\cdot\frac{x^2 - x}{6}Multiply each by its y-value and add.
P(x) = \frac{2x^2 - 8x + 6}{6} - \frac{9x^2 - 27x}{6} + \frac{13x^2 - 13x}{6}Rewrite over the common denominator 6.
P(x) = \frac{6x^2 + 6x + 6}{6}Combine like terms: 2 − 9 + 13 = 6 and −8 + 27 − 13 = 6.
P(x) = x^2 + x + 1
Divide each term by 6.
Answer: P(x) = x² + x + 1. Check: P(0) = 1, P(1) = 3 and P(3) = 9 + 3 + 1 = 13.
Example 3: Estimating ln 3 from a table
A table gives ln 1 = 0, ln 2 ≈ 0.693147 and ln 4 ≈ 1.386294. Use quadratic interpolation to estimate ln 3, and find the error.
L_0(3) = \frac{(3 - 2)(3 - 4)}{(1 - 2)(1 - 4)} = \frac{-1}{3}Substitute x = 3 into L₀ for the nodes 1, 2, 4.
L_1(3) = \frac{(3 - 1)(3 - 4)}{(2 - 1)(2 - 4)} = \frac{-2}{-2} = 1Substitute into L₁.
L_2(3) = \frac{(3 - 1)(3 - 2)}{(4 - 1)(4 - 2)} = \frac{2}{6} = \frac{1}{3}Substitute into L₂.
P(3) = 0\left(-\frac{1}{3}\right) + 0.693147(1) + 1.386294\left(\frac{1}{3}\right)Multiply by the y-values and add.
P(3) = 0 + 0.693147 + 0.462098
Multiply.
P(3) = 1.155245
Add.
|P(3) - \ln 3| = |1.155245 - 1.098612| = 0.056633
Compare with ln 3 ≈ 1.098612 (see absolute error).
Answer: ln 3 ≈ 1.155245, with an error of about 0.057. The estimate is rough because the nodes are far apart; Interpolation Error shows how to bound this error.
Example 4: A cubic evaluated at one point
Four points are (−1, 2), (0, 1), (1, 0) and (2, 5). Estimate the value of the interpolating cubic at x = 0.5 without expanding P(x).
L_0(0.5) = \frac{(0.5 - 0)(0.5 - 1)(0.5 - 2)}{(-1 - 0)(-1 - 1)(-1 - 2)} = \frac{0.375}{-6} = -0.0625Substitute x = 0.5 into L₀.
L_1(0.5) = \frac{(0.5 + 1)(0.5 - 1)(0.5 - 2)}{(0 + 1)(0 - 1)(0 - 2)} = \frac{1.125}{2} = 0.5625Substitute into L₁.
L_2(0.5) = \frac{(0.5 + 1)(0.5 - 0)(0.5 - 2)}{(1 + 1)(1 - 0)(1 - 2)} = \frac{-1.125}{-2} = 0.5625Substitute into L₂.
L_3(0.5) = \frac{(0.5 + 1)(0.5 - 0)(0.5 - 1)}{(2 + 1)(2 - 0)(2 - 1)} = \frac{-0.375}{6} = -0.0625Substitute into L₃.
P(0.5) = 2(-0.0625) + 1(0.5625) + 0(0.5625) + 5(-0.0625)
Multiply by the y-values and add.
P(0.5) = -0.125 + 0.5625 + 0 - 0.3125 = 0.125
Multiply, then add.
Answer: P(0.5) = 0.125. A useful check: the four L-values add to −0.0625 + 0.5625 + 0.5625 − 0.0625 = 1, which is always true (Practice Problem 7).
Example 5: Estimating a temperature
A weather station records 50°F at 6 am, 62°F at 9 am and 68°F at noon. Let t be hours after 6 am. Use quadratic interpolation to estimate the temperature at 10 am.
(t_0, t_1, t_2) = (0, 3, 6), \; t = 4
10 am is 4 hours after 6 am.
L_0(4) = \frac{(4 - 3)(4 - 6)}{(0 - 3)(0 - 6)} = \frac{-2}{18} = -\frac{1}{9}Substitute into L₀.
L_1(4) = \frac{(4 - 0)(4 - 6)}{(3 - 0)(3 - 6)} = \frac{-8}{-9} = \frac{8}{9}Substitute into L₁.
L_2(4) = \frac{(4 - 0)(4 - 3)}{(6 - 0)(6 - 3)} = \frac{4}{18} = \frac{2}{9}Substitute into L₂.
P(4) = 50\left(-\frac{1}{9}\right) + 62\left(\frac{8}{9}\right) + 68\left(\frac{2}{9}\right)Multiply by the temperatures and add.
P(4) = \frac{-50 + 496 + 136}{9} = \frac{582}{9}Use the common denominator 9.
P(4) \approx 64.7
Divide.
Answer: about 64.7°F at 10 am. A straight line between 9 am and noon would give 64°F; the quadratic also uses the faster warming between 6 and 9 am.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Including the node’s own factor | Putting (x − x₁) in L₁(x) | Lₖ uses every factor except (x − xₖ); otherwise it is 0 at its own node. |
| Wrong denominator | Using (x₁ − x₀)(x₁ − x₂) in L₀ | The denominator is the numerator evaluated at x = xₖ: for L₀ it is (x₀ − x₁)(x₀ − x₂). |
| Sign slips in the denominator | (0 − 1)(0 − 3) = −3 | Two negatives multiply to a positive: (−1)(−3) = 3. |
| Repeated x-values | Nodes (1, 2) and (1, 5) | A denominator becomes 0. Interpolation needs distinct x-values. |
| Expanding when you only need one value | Expanding a cubic to find P(0.5) | Substitute the x-value into each Lₖ first, as in Example 4. |
| Trusting values far outside the nodes | Using Example 3’s quadratic to estimate ln 5 | Extrapolation can be very wrong: P(5) ≈ 1.386 but ln 5 ≈ 1.609. |
Related methods
Solving for the coefficients
You can also write P(x) = a + bx + cx² and substitute each point to get a linear system for a, b and c, as in systems of equations in three variables. By the uniqueness theorem the answer is the same polynomial, but the Lagrange form skips solving the system.
Newton’s form and adding points
If a new data point arrives, every Lagrange basis polynomial changes. Newton’s Divided Differences, the next lesson, builds the same polynomial one point at a time, so adding a point only adds one term.
Interpolation error and Taylor polynomials
A Taylor polynomial matches a function’s derivatives at one point; an interpolating polynomial matches its values at several points. Both have error formulas built on a higher derivative, and using many equally spaced nodes can make interpolation worse, not better (Runge’s phenomenon, covered in Interpolation Error).
Practice problems
- Find the Lagrange polynomial through (2, 5) and (6, 13), and use it to estimate the value at x = 3.
- For the nodes 0, 1 and 2, write L₀(x), L₁(x) and L₂(x), and check that they add to 1 at x = 1.5.
- Find the polynomial of degree at most 2 through (1, 2), (2, 3) and (3, 6).
- Use √1 = 1, √4 = 2 and √9 = 3 to estimate √5 by quadratic interpolation.
- The points (0, 1), (1, 2), (2, 9) and (3, 28) lie on a cubic. Use Lagrange interpolation to find its value at x = 1.5.
- Explain why no polynomial interpolates (1, 2), (1, 5) and (3, 4).
- Explain why \sum_{k=0}^{n} L_k(x) = 1 for every x.
- Use sin 0° = 0, sin 30° = 0.5 and sin 90° = 1 to estimate sin 45° by quadratic interpolation in degrees.
- How many points do you need to determine a polynomial of degree at most 4? What degree can the interpolating polynomial through 7 points have?
- A car is at 0 m at t = 0 s, 30 m at t = 2 s and 100 m at t = 5 s. Estimate its position at t = 3 s.
Show answers
1.
L_0(x) = \frac{x - 6}{2 - 6} = -\frac{x - 6}{4}Basis polynomial for x₀ = 2.
L_1(x) = \frac{x - 2}{6 - 2} = \frac{x - 2}{4}Basis polynomial for x₁ = 6.
P(x) = -\frac{5(x - 6)}{4} + \frac{13(x - 2)}{4}Multiply by the y-values and add.
P(x) = \frac{-5x + 30 + 13x - 26}{4}Distribute over the common denominator.
P(x) = \frac{8x + 4}{4} = 2x + 1Combine like terms and divide.
P(3) = 2(3) + 1 = 7
Substitute x = 3.
Answer: P(x) = 2x + 1 and P(3) = 7
2.
L_0(x) = \frac{(x - 1)(x - 2)}{(0 - 1)(0 - 2)} = \frac{(x - 1)(x - 2)}{2}Denominator (−1)(−2) = 2.
L_1(x) = \frac{(x - 0)(x - 2)}{(1 - 0)(1 - 2)} = -x(x - 2)Denominator (1)(−1) = −1.
L_2(x) = \frac{(x - 0)(x - 1)}{(2 - 0)(2 - 1)} = \frac{x(x - 1)}{2}Denominator (2)(1) = 2.
L_0(1.5) + L_1(1.5) + L_2(1.5) = -0.125 + 0.75 + 0.375 = 1
Substitute x = 1.5 and add.
Answer: the three values add to 1.
3.
L_0(x) = \frac{(x - 2)(x - 3)}{(1 - 2)(1 - 3)} = \frac{x^2 - 5x + 6}{2}Denominator (−1)(−2) = 2.
L_1(x) = \frac{(x - 1)(x - 3)}{(2 - 1)(2 - 3)} = -(x^2 - 4x + 3)Denominator (1)(−1) = −1.
L_2(x) = \frac{(x - 1)(x - 2)}{(3 - 1)(3 - 2)} = \frac{x^2 - 3x + 2}{2}Denominator (2)(1) = 2.
P(x) = (x^2 - 5x + 6) - 3(x^2 - 4x + 3) + 3(x^2 - 3x + 2)
Multiply by 2, 3 and 6 and simplify each fraction.
P(x) = x^2 - 2x + 3
Combine like terms: 1 − 3 + 3 = 1, −5 + 12 − 9 = −2, 6 − 9 + 6 = 3.
Answer: P(x) = x² − 2x + 3
4.
L_0(5) = \frac{(5 - 4)(5 - 9)}{(1 - 4)(1 - 9)} = \frac{-4}{24} = -\frac{1}{6}Nodes 1, 4, 9; substitute x = 5.
L_1(5) = \frac{(5 - 1)(5 - 9)}{(4 - 1)(4 - 9)} = \frac{-16}{-15} = \frac{16}{15}Substitute into L₁.
L_2(5) = \frac{(5 - 1)(5 - 4)}{(9 - 1)(9 - 4)} = \frac{4}{40} = \frac{1}{10}Substitute into L₂.
P(5) = 1\left(-\frac{1}{6}\right) + 2\left(\frac{16}{15}\right) + 3\left(\frac{1}{10}\right) = \frac{-5 + 64 + 9}{30}Multiply and use the common denominator 30.
P(5) = \frac{68}{30} \approx 2.266667Divide.
Answer: √5 ≈ 2.2667 (the true value is 2.236068…, so the error is about 0.031)
5.
L_0(1.5) = \frac{(1.5 - 1)(1.5 - 2)(1.5 - 3)}{(0 - 1)(0 - 2)(0 - 3)} = \frac{0.375}{-6} = -0.0625Substitute into L₀.
L_1(1.5) = \frac{(1.5 - 0)(1.5 - 2)(1.5 - 3)}{(1 - 0)(1 - 2)(1 - 3)} = \frac{1.125}{2} = 0.5625Substitute into L₁.
L_2(1.5) = \frac{(1.5 - 0)(1.5 - 1)(1.5 - 3)}{(2 - 0)(2 - 1)(2 - 3)} = \frac{-1.125}{-2} = 0.5625Substitute into L₂.
L_3(1.5) = \frac{(1.5 - 0)(1.5 - 1)(1.5 - 2)}{(3 - 0)(3 - 1)(3 - 2)} = \frac{-0.375}{6} = -0.0625Substitute into L₃.
P(1.5) = 1(-0.0625) + 2(0.5625) + 9(0.5625) + 28(-0.0625)
Multiply by the y-values and add.
P(1.5) = -0.0625 + 1.125 + 5.0625 - 1.75 = 4.375
Multiply, then add.
Answer: 4.375. The points lie on y = x³ + 1, and by uniqueness the interpolating cubic is that same cubic: 1.5³ + 1 = 4.375.
6.
x_0 - x_1 = 1 - 1 = 0
The denominators of L₀ and L₁ contain this factor.
Answer: the formula would divide by 0. More basically, a function cannot take two values, 2 and 5, at the same x = 1.
7.
Answer: the constant function 1 passes through the points (xₖ, 1). Interpolating it gives \sum 1\cdot L_k(x), a polynomial of degree at most n through those points. The constant 1 is also such a polynomial, so by uniqueness they are equal for every x.
8.
L_0(45) = \frac{(45 - 30)(45 - 90)}{(0 - 30)(0 - 90)} = \frac{-675}{2700} = -0.25Nodes 0, 30, 90; substitute x = 45.
L_1(45) = \frac{(45 - 0)(45 - 90)}{(30 - 0)(30 - 90)} = \frac{-2025}{-1800} = 1.125Substitute into L₁.
L_2(45) = \frac{(45 - 0)(45 - 30)}{(90 - 0)(90 - 30)} = \frac{675}{5400} = 0.125Substitute into L₂.
P(45) = 0(-0.25) + 0.5(1.125) + 1(0.125) = 0.6875
Multiply by the y-values and add.
Answer: sin 45° ≈ 0.6875 (the true value is 0.707107…, so the error is about 0.020)
9.
Answer: 5 points determine a polynomial of degree at most 4. Through 7 points the interpolating polynomial has degree at most 6 (it can be lower, for example if the points lie on a line).
10.
L_0(3) = \frac{(3 - 2)(3 - 5)}{(0 - 2)(0 - 5)} = \frac{-2}{10} = -0.2Nodes 0, 2, 5; substitute t = 3.
L_1(3) = \frac{(3 - 0)(3 - 5)}{(2 - 0)(2 - 5)} = \frac{-6}{-6} = 1Substitute into L₁.
L_2(3) = \frac{(3 - 0)(3 - 2)}{(5 - 0)(5 - 2)} = \frac{3}{15} = 0.2Substitute into L₂.
P(3) = 0(-0.2) + 30(1) + 100(0.2) = 50
Multiply by the positions and add.
Answer: about 50 m
Lagrange interpolation FAQ
What is the Lagrange interpolation formula?
P(x) = \sum_{k=0}^{n} y_k L_k(x) with L_k(x) = \prod_{j \ne k} \frac{x - x_j}{x_k - x_j}. Each Lₖ is 1 at xₖ and 0 at the other nodes.
What degree is the Lagrange polynomial?
At most n for n + 1 points. Three points give a polynomial of degree at most 2, four points give degree at most 3, and so on.
Is the Lagrange polynomial unique?
Yes. Only one polynomial of degree at most n passes through n + 1 points with distinct x-values. Other methods, such as Newton’s divided differences, give the same polynomial in a different form.
What is the difference between interpolation and extrapolation?
Interpolation estimates values between the nodes; extrapolation estimates values outside them. Interpolating polynomials can be badly wrong when extrapolating, as the ln 5 example in the mistakes table shows.
Summary
- Lagrange interpolation builds the unique polynomial of degree at most n through n + 1 points with distinct x-values.
- Basis polynomials: L_k(x) = \prod_{j \ne k} \frac{x - x_j}{x_k - x_j}, equal to 1 at xₖ and 0 at the other nodes.
- The interpolant is P(x) = \sum y_k L_k(x).
- To estimate a single value, substitute x into each Lₖ first; the L-values always add to 1.
- Estimates between nodes are usually good; estimates outside the nodes can be poor.
Previous lesson: Order of Convergence
Next lesson: Newton’s Divided Differences
Back to the Numerical Methods Index