Interpolation Using Lagrange Polynomials in Numerical Analysis: A Complete Tutorial
Interpolation using Lagrange polynomials is one of the most widely used techniques in numerical analysis for constructing a polynomial that passes through a given set of data points. As an interpolation method, it provides a direct way to build a polynomial from discrete data points.
The Lagrange interpolation method constructs the interpolating polynomial directly by combining specially designed basis polynomials, each of which contributes to exactly one data point.
In this tutorial, you’ll learn the theory behind Lagrange interpolation, discover why the method works, examine situations in which it succeeds and fails, derive and interpret the interpolation error formula, follow a step-by-step procedure for constructing interpolating polynomials, and work through detailed examples that illustrate the method from start to finish.
What Are Lagrange Polynomials?
Suppose you are given a collection of data points
$$(x_0, y_0), \ldots, (x_n, y_n),$$
where each \( x_i \) is distinct. The goal of interpolation is to find a polynomial that passes through every one of these points. This polynomial is called the interpolating polynomial.
At first glance, this may seem like a difficult problem. One approach would be to begin with a general polynomial of degree \( n \),
$$P(x) = a_0 + \cdots + a_nx^n,$$
and substitute each data point into the equation. Doing so produces a system of \( (n + 1) \times (n + 1) \) linear equations in the unknown coefficients \( a_0, \ldots, a_n \). This system can then be solved using Gaussian elimination.
If you need a refresher on solving systems of equations, see our article How to Solve a System of Equations Using Gaussian Elimination: A Step-by-Step Guide, where we discuss the process in detail.
Although this approach works, it quickly becomes tedious as the number of data points increases. Lagrange interpolation provides a solution by constructing the interpolating polynomial, without first solving a system of equations.
Lagrange Basis Polynomials
Rather than solving for the coefficients of a polynomial, the Lagrange interpolation method builds the interpolating polynomial from a collection of simpler polynomials called Lagrange basis polynomials.
Each basis polynomial is designed to satisfy two important conditions:
- It equals \( 1 \) at one interpolation point.
- It equals \( 0 \) at every other interpolation point.
Because of these properties, each basis polynomial contributes the value of exactly one data point while ignoring all the others.
The polynomials form a basis as discussed in the article The Ultimate Guide to Understanding Basis and Dimension in Vector Spaces.
For the data point \( x_i \), the corresponding Lagrange basis polynomial is
$$L_i(x) = \prod_{j = 0, j \ne i}^{n}\frac{x – x_j}{x_i – x_j}.$$
Notice that every factor in the numerator contains \( x – x_j \), while the denominator contains the constant \( x_i – x_j \). This normalization ensures that
$$L_i(x_i) = 1$$
and
$$L_i(x_j) = 0,\qquad j\ne i.$$
Constructing the Interpolating Polynomial
Once the basis polynomials have been constructed, the interpolating polynomial is obtained by multiplying each basis polynomial by its corresponding function value and adding the results together:
$$P(x) = \sum_{i=0}^{n} y_iL_i(x).$$
Expanding the summation gives
$$P(x) = y_0L_0(x) + y_1L_1(x) + \cdots + y_nL_n(x).$$
Each term contributes only the information from its associated data point. Since every basis polynomial is zero at the other data points, the polynomial satisfies
$$P(x_i) = y_i,\qquad i=0,1,\ldots,n.$$
In other words, the interpolating polynomial passes through every given data point.
Why Does Lagrange Interpolation Work?
The Lagrange interpolation formula may initially look like a clever trick. We construct a collection of basis polynomials, multiply each one by a corresponding function value, and add everything together. But why does this process produce a polynomial that passes through all of the given data points?
The answer lies in the special properties of the Lagrange basis polynomials. Each basis polynomial is constructed so that it is \( 1 \) at one interpolation point and \( 0 \) at every other interpolation point. These properties allow the individual terms in the interpolation formula to work together without interfering with one another.
The Key Property of the Lagrange Basis Polynomials
Recall that the \( i \)-th Lagrange basis polynomial is
$$L_i(x) = \prod_{j = 0, j \ne i}^{n}\frac{x – x_j}{x_i – x_j}.$$
Let’s evaluate this polynomial at one of the interpolation points, \( x_k \).
There are two cases to consider.
First, suppose \( k = i \). Substituting \( x = x_i \) gives
$$L_i(x_i) = \prod_{j = 0, j \ne i}^{n} \frac{x_i – x_j}{x_i – x_j}.$$
Every factor is equal to \( 1 \), so
$$L_i(x_i) = 1.$$
Now suppose \( k \ne i \). When we evaluate \( L_i(x) \) at \( x = x_k \), one of the factors in the numerator becomes
$$x_k – x_k = 0.$$
Therefore,
$$L_i(x_k) = 0, k \ne i.$$
Together, these two results can be summarized as
$$L_i(x_k) = \begin{cases}
1, & i = k,\\
0, & i \ne k
\end{cases}.$$
How the Basis Polynomials Reproduce the Data
The Lagrange interpolating polynomial is
$$P(x) = \sum_{i = 0}^{n} y_iL_i(x).$$
To see why this polynomial passes through every data point, evaluate it at \( x = x_k \):
$$P(x_k) = \sum_{i = 0}^{n} y_iL_i(x_k).$$
Because \( L_k(x_k) = 1 \) and every other basis polynomial is zero at \( x_k \), all of the terms disappear except the \( k \)-th term:
$$P(x_k) = y_0(0) + \cdots + y_k(1) + \cdots + y_n(0).$$
Therefore,
$$P(x_k) = y_k.$$
Since this is true for every \( k = 0, \ldots, n \), the polynomial \( P(x) \) passes through every one of the given data points.
This is the central idea behind Lagrange interpolation: each basis polynomial acts like a switch that turns on one data value while turning off all the others.
Why the Interpolating Polynomial Is Unique
The Lagrange formula does more than produce an interpolating polynomial. It produces the unique polynomial of degree \( n \) that pass through \( n+1 \) distinct data points.
To understand why, suppose there were two different polynomials, \( P(x) \) and \( Q(x) \), each of degree \( n \), that pass through the same \( n + 1 \) points.
Then their difference,
$$R(x) = P(x) – Q(x),$$
would also be a polynomial of degree \( n \).
Because \( P(x) \) and \( Q(x) \) agree at every data point,
$$P(x_i) = Q(x_i),$$
so
$$R(x_i) = 0$$
for all \( i = 0, \ldots, n \).
Thus, \( R(x) \) would have \( n + 1 \) distinct roots. However, a nonzero polynomial of degree \( n \) cannot have more than \( n \) distinct roots. Therefore, \( R(x) \) must be the zero polynomial:
$$R(x) = 0.$$
This means
$$P(x) = Q(x).$$
Consequently, there can be only one polynomial of degree \( n \) that passes through \( n + 1 \) distinct data points.
When Does Lagrange Interpolation Succeed?
The success of Lagrange interpolation depends on how the interpolation problem is set up. When the function is sufficiently smooth, the interpolation points are chosen appropriately, and the number of points is small, Lagrange interpolation can provide a good approximation to the underlying function.
Understanding when the method performs well is important because interpolation is not simply a matter of finding a polynomial that passes through a collection of points. A polynomial can pass through every data point while still providing a poor approximation between those points.
Smooth, Continuous Functions
Lagrange interpolation generally performs well when the function being approximated is smooth over the interval of interest. A smooth function does not have abrupt changes, discontinuities, or sharp irregularities that are difficult for a polynomial to reproduce.
For a review of continuous functions, please refer to the article A Complete Introduction to the Bisection Method with Worked Examples and Solutions. For a review of smooth functions, please refer to the articles Newton’s Method Explained for Beginners and The Ultimate Resource for Understanding the Secant Method.
A Small Number of Interpolation Points
Lagrange interpolation is particularly useful when only a small number of data points are available. Given \( n + 1 \) distinct points, the method constructs a polynomial of degree at most \( n \).
Using a small number of points has two important benefits. First, the resulting polynomial has a low degree. Second, constructing and evaluating the Lagrange polynomial is manageable.
Well-Distributed Interpolation Points
The location of the interpolation points has a significant effect on the accuracy of the approximation. When the points are reasonably distributed throughout the interval, Lagrange interpolation often performs well.
If the interpolation points are spread out rather than concentrated in one region, the polynomial generally has a better opportunity to approximate the function across the entire interval.
Interpolation Within the Data Range
Lagrange polynomials are designed primarily for interpolation, meaning that the point where we want to estimate the function lies within the range of the known data. Within the interval containing the interpolation points, the polynomial is constrained by the known data. Outside that interval, however, the polynomial can behave very differently from the underlying function.
Interpolation of Polynomials
One of the strongest situations for Lagrange interpolation occurs when the function being interpolated is itself a polynomial of sufficiently low degree.
Suppose the function is a polynomial of degree \( n \), and we have \( n+1 \) distinct data points. The Lagrange interpolation polynomial \( P(x) \) has degree \( n \) and agrees with \( f(x) \) at all \( n + 1 \) data points.
Because the interpolating polynomial is unique, there is no interpolation error. The method does not merely approximate the function; it reproduces it exactly.
Short Intervals
Lagrange interpolation can also be particularly effective when applied over a short interval. Even functions with significant curvature can often be approximated accurately when the interpolation interval is sufficiently small.
For example, instead of attempting to approximate a function over a very large interval with one high-degree polynomial, we can interpolate it over smaller intervals using lower-degree polynomials.
When There is Enough Information
Interpolation requires a sufficient number of distinct data points to construct the desired polynomial. If we want a polynomial of degree \( n \), we need \( n + 1 \) distinct data points.
The data points must also have distinct \( x \)-values. If two points have the same \( x \)-coordinate but different \( y \)-values, then no function, and therefore no polynomial, can pass through both points.
The next section examines cases in which Lagrange interpolation fails and explains why a polynomial that passes exactly through every data point can still produce a poor approximation.
When Does Lagrange Interpolation Fail?
Although Lagrange interpolation can produce highly accurate results, it is not guaranteed to provide a good approximation in every situation. In particular, problems can arise when too many data points are used, when the points are poorly distributed, or when the polynomial is used outside the interval containing the data.
Runge’s Phenomenon
One of the most important limitations of polynomial interpolation is Runge’s phenomenon. This occurs when a high-degree polynomial constructed from equally spaced points develops large oscillations, particularly near the endpoints of the interpolation interval.
Too Many Data Points
The degree of the Lagrange polynomial increases as more data points are added. Given \( n + 1 \) data points, the resulting polynomial has degree \( n \). High-degree polynomials can be problematic because they can develop large oscillations. They can also become more sensitive to small changes in the data.
Poorly Chosen Data Points
The location of the data points can have a major effect on the quality of the approximation.
Suppose the points are heavily clustered in one part of the interval while leaving large gaps elsewhere. The resulting polynomial may approximate the function very well near the clustered points but behave poorly in regions where there is little data.
Extrapolation Outside the Data Range
Lagrange interpolation becomes particularly unreliable when it is used for extrapolation. Outside the interpolation interval, no data points are constraining the behavior of the polynomial. Consequently, even a small difference between the interpolating polynomial and the underlying function can grow rapidly as we move farther away from the known data.
This makes extrapolation substantially more unreliable than interpolation.
Discontinuous or Nonsmooth Functions
Polynomial interpolation can also struggle when the underlying function contains discontinuities or isn’t smooth.
For example, consider a function with a jump discontinuity. A polynomial is continuous, so it cannot reproduce the discontinuity.
Similarly, a function with a sharp corner may require a high-degree polynomial to approximate its behavior accurately. Increasing the degree, however, can introduce unwanted oscillations.
Noisy Data
Lagrange interpolation assumes that the supplied data points should be matched exactly. This can be problematic when the data come from physical measurements or experiments. Real-world measurements often contain some degree of error.
Lagrange interpolation will construct a polynomial that passes exactly through these noisy measurements. As a result, the polynomial may reproduce the measurement errors rather than reveal the underlying trend.
Numerical Instability for Large Datasets
The Lagrange interpolation formula can become inefficient as the number of data points increases. For small datasets, this is generally not a significant concern. For large datasets, other interpolation methods may be more efficient.
Lagrange interpolation constructs a polynomial that passes through the specified data points. The challenge is determining whether that polynomial also provides a useful approximation to the function between those points. To answer that question quantitatively, we need to examine the interpolation error.
Error in Lagrange Interpolation
One of the most important questions in numerical analysis is not simply whether an interpolating polynomial passes through the known data points, but how accurately it approximates the underlying function between those points.
As we saw earlier, the Lagrange interpolation polynomial satisfies
$$P(x_i) = f(x_i)$$
at every data point \( x_i \). Therefore, the interpolation error is exactly zero at the known data points. However, at points between the data points, the polynomial may not exactly equal the function value.
The interpolation error measures this error.
The Interpolation Error
Let \( f(x) \) be a function and let \( P_n(x) \) be its Lagrange interpolation polynomial constructed from \( n+1 \) data points
$$x_0, \ldots, x_n.$$
The interpolation error at a point \( x \) is defined as
$$\epsilon_n(x) = f(x) – P_n(x).$$
At each data point \( x_i \),
$$\epsilon_n(x_i) = f(x_i) – P_n(x_i) = 0.$$
This is expected because the interpolating polynomial is constructed to pass through every known data point.
The more interesting question is what happens when \( x \) is not one of the data points.
The Lagrange Interpolation Error Formula
If \( f \) has \( n + 1 \) continuous derivatives on an interval containing the data points and \( x \), then the interpolation error can be written as
$$\epsilon_n(x) = \frac{f^{(n+1)}(\xi)}{(n+1)!}(x – x_0)(x – x_1) \cdots (x – x_n),$$
where \( \xi \) is some number within the interval containing the data points and \( x \).
This is known as the Lagrange interpolation error formula or the Lagrange remainder formula.
Notice that a derivative appears in this formula. For a review of derivatives, please refer to the article How to Differentiate a Function Step by Step: A Beginner’s Guide.
Interpreting the Error Formula
The error formula tells us several important things about interpolation.
First, the error depends on the \( (n + 1) \)-st derivative of the function. If this derivative remains bounded throughout the interval, the interpolation error tends to be smaller.
Second, the error depends on the location of the data points. Even if the function is smooth, poorly chosen data points can result in a large error.
Third, the factorial term
$$(n + 1)!$$
appears in the denominator. This can cause the error to decrease rapidly when the derivatives and data points remain bounded. However, this does not mean that increasing \( n \) will always decrease the error. As discussed earlier, the product of the factors involving the data points can become large, particularly for poorly chosen data points.
Deriving an Error Bound
The error formula contains an unknown value \( \xi \), so we generally cannot calculate the exact error directly from it. However, we can use it to obtain an error bound.
Suppose that
$$|f^{(n+1)}(t)| \leq M$$
for every \( t \) in the interval containing the data points and the point \( x \).
Then
$$|f^{(n + 1)}(\xi)| \leq M.$$
Taking the absolute value of the error formula gives
$$|\epsilon_n(x)| = |\frac{f^{(n+1)}(\xi)}{(n+1)!}(x – x_0)(x – x_1) \cdots (x – x_n)|.$$
Therefore,
$$|\epsilon_n(x)| \leq \frac{M}{(n+1)!}|(x – x_0)(x – x_1) \cdots (x – x_n)|.$$
Equivalently,
$$|\epsilon_n(x)| \leq \frac{M}{(n + 1)!}\prod_{i = 0}^{n}{|x – x_i|}.$$
This gives us a practical way to estimate the maximum possible interpolation error.
In the next section, we’ll put the theory into practice by following a step-by-step procedure for interpolation using Lagrange polynomials.
Step-by-Step Procedure for Interpolation Using Lagrange Polynomials
Now that we understand the theory behind Lagrange interpolation and the factors that affect its accuracy, we can turn our attention to the actual process of constructing an interpolating polynomial.
Step 1: List the Data Points
Begin by identifying all of the known data points.
Step 2: Write the Lagrange Basis Polynomials
For each data point \( x_i \), construct a corresponding Lagrange basis polynomial:
$$L_i(x) = \prod_{j = 0, j \ne i}^{n}\frac{x – x_j}{x_i – x_j}.$$
Step 3: Multiply Each Basis Polynomial by Its Corresponding Data Value
Once the basis polynomials have been constructed, multiply each one by the corresponding \( y_i \).
Step 4: Add the Terms Together
The Lagrange interpolation polynomial is obtained by adding all the terms:
$$P_n(x) = \sum_{i = 0}^{n} y_iL_i(x).$$
Step 5: Evaluate the Interpolating Polynomial
If the goal is to estimate the value of the function at some point \( x = a \), substitute \( a \) into the interpolating polynomial:
If \( a \) lies between the smallest and largest data points, this is an interpolation problem. If \( a \) lies outside that range, the calculation becomes extrapolation and should be treated with greater caution.
In the next section, we’ll apply these steps to actual interpolation problems.
Worked Out Examples
The first example shows how to construct a Lagrange polynomial.
Example 1: Find the Lagrange polynomial that passes through the points \( (0,1) \), \( (1,3) \), and \( (2,7) \).
Solution: The Lagrange polynomial is given by
$$y = 1\frac{(x – 1)(x – 2)}{(0 – 1)(0 – 2)} + 3\frac{(x – 0)(x – 2)}{(1 – 0)(1 – 2)} + 7\frac{(x – 0)(x – 1)}{(2 – 0)(2 – 1)}.$$
Multiplying the binomials in the numerators, we obtain
$$y = 1\frac{x^2 – 2x – x + 2}{(0 – 1)(0 – 2)} + 3\frac{x^2 – 2x – 0x + 0}{(1 – 0)(1 – 2)} + 7\frac{x^2 – x – 0x + 0}{(2 – 0)(2 – 1)}.$$
Adding and subtracting gives
$$y = 1\frac{x^2 – 3x + 2}{(–1)(–2)} + 3\frac{x^2 – 2x}{(1)(-1)} + 7\frac{x^2 – x}{(2)(1)}.$$
Simplifying the denominators, this is
$$y = 1\frac{x^2 – 3x + 2}{2} + 3\frac{x^2 – 2x}{-1} + 7\frac{x^2 – x}{2},$$
which is equivalent to
$$y = \frac{1}{2}(x^2 – 3x + 2) – 3(x^2 – 2x) + \frac{7}{2}(x^2 – x).$$
Distributing we find
$$y = \frac{1}{2}x^2 – \frac{3}{2}x + 1 – 3x^2 + 6x + \frac{7}{2}x^2 – \frac{7}{2}x.$$
Combining like terms, we arrive at a final answer of
$$y = x^2 + x + 1.$$
The next example shows how to use Lagrange interpolation to approximate a function value.
Example 2: Approximate the value of \( e^{0.5} \) by constructing the Lagrange polynomial that passes through the points at \( x = 0 \), \( x = 1 \), and \( x = 2 \). Determine the absolute error.
Solution: We want to find the Lagrange polynomial passing through the points
$$\{ (0, e^0), (1, e^1), (2, e^2) \}.$$
Evaluating the exponentials, this is
$${ (0, 1), (1, 2.718281), (2, 7.389056) }.$$
The Lagrange polynomial is then
$$y = 1\frac{(x – 1)(x – 2)}{(0 – 1)(0 – 2)} + 2.718281\frac{(x – 0)(x – 2)}{(1 – 0)(1 – 2)} + 7.389056\frac{(x – 0)(x – 1)}{(2 – 0)(2 – 1)}.$$
Evaluating at \( x = 0.5 \) we find
$$y(0.5) = 1\frac{(0.5 – 1)(0.5 – 2)}{(0 – 1)(0 – 2)} + 2.718281\frac{(0.5 – 0)(0.5 – 2)}{(1 – 0)(1 – 2)} + 7.389056\frac{(0.5 – 0)(0.5 – 1)}{(2 – 0)(2 – 1)}.$$
Subtracting gives
$$y(0.5) = 1\frac{(-0.5)(-1.5)}{(–1)(–2)} + 2.718281\frac{(0.5)(-1.5)}{(1)(-1)} + 7.389056\frac{(0.5)(-0.5)}{(2)(1)}.$$
Multiplying this is
$$y(0.5) = 1\frac{(0.75)}{2} + 2.718281\frac{-0.75}{-1} + 7.389056\frac{(-0.25)}{2}.$$
which is equivalent to
$$y(0.5) = 1(0.375) + 2.718281(0.75) + 7.389056(-0.125).$$
Multiplying we find
$$y(0.5) = 0.375 + 2.038711 – 0.923632.$$
Adding we arrive at
$$y(0.5) = 1.490079.$$
The absolute error is then
$$\epsilon = |e^{0.5} – 1.490079|.$$
Evaluating the exponential, this is
$$\epsilon = |1.648721 – 1.490079|.$$
Subtracting gives
$$\epsilon = |0.158641|.$$
Taking the absolute value, we arrive at a final answer of
$$\epsilon = 0.158641.$$
The final example shows how to use Lagrange interpolation to approximate the value of a missing data point.
Example 3: Approximate the value at \( x = 1.5 \) by constructing the Lagrange polynomial that passes through the set of data points $$\{ (0, 1), (1, 3), (2, 2), (3, 5) \}.$$
Solution: The Lagrange polynomial is
$$y = 1\frac{(x – 1)(x – 2)(x – 3)}{(0 – 1)(0 – 2)(0 – 3)} + 3\frac{(x – 0)(x – 2)(x – 3)}{(1 – 0)(1 – 2)(1 – 3)} + 2\frac{(x – 0)(x – 1)(x – 3)}{(2 – 0)(2 – 1)(2 – 3)} + 5\frac{( x – 0)(x – 1)(x – 2)}{(3 – 0)(3 – 1)(3 – 2)}.$$
Evaluating at \( x = 1.5 \) we find
$$y(1.5) = 1\frac{(1.5 – 1)(1.5 – 2)(1.5 – 3)}{(0 – 1)(0 – 2)(0 – 3)} + 3\frac{(1.5 – 0)(1.5 – 2)(1.5 – 3)}{(1 – 0)(1 – 2)(1 – 3)} + 2\frac{(1.5 – 0)(1.5 – 1)(1.5 – 3)}{(2 – 0)(2 – 1)(2 – 3)} + 5\frac{(1.5 – 0)(1.5 – 1)(1.5 – 2)}{(3 – 0)(3 – 1)(3 – 2)}.$$
Subtracting gives
$$y(1.5) = 1\frac{(0.5)(-0.5)(-1.5)}{(–1)(–2)(-3)} + 3\frac{(1.5)(-0.5)(-1.5)}{(1)(-1)(-2)} + 2\frac{(1.5)(0.5)(-1.5)}{(2)(1)(-1)} + 5\frac{(1.5)(0.5)(-0.5)}{(3)(2)(1)}.$$
Multiplying this is
$$y(1.5) = 1\frac{0.375}{–6} + 3\frac{1.125}{2} + 2\frac{-1.125}{-2} + 5\frac{(-0.375}{6}.$$
which is equivalent to
$$y(1.5) = 1(–0.0625) + 3(0.5625) + 2(0.5625) + 5(-0.0625).$$
Multiplying we find
$$y(1.5) = -0.0625 + 1.6875 + 1.125 – 0.3125.$$
Adding and subtracting, we arrive at a final answer of
$$y(1.5) = 2.4375.$$
Conclusion
Interpolation using Lagrange polynomials provides a way to construct a polynomial that passes through a given set of distinct data points. By combining Lagrange basis polynomials with the corresponding function values, we can construct an interpolating polynomial without having to solve a system of equations.
Throughout this tutorial, we saw why the method works and established that \( n + 1 \) distinct data points determine a unique polynomial of degree \( n \).
We also examined the situations in which Lagrange interpolation succeeds and fails. The interpolation error formula provides a way to quantify these limitations. Finally, the worked examples demonstrated the complete process, from constructing the individual basis polynomials to forming the final interpolating polynomial and using it to estimate unknown function values.
Further Reading
Basic Integration Problems for Beginners – Now that you understand interpolation, I now recommend reviewing integration as interpolation is often used to solve integrals numerically.
