I wrote this calculator to be able to verify solutions for Lagrange's interpolation problems. In these problems you are often asked to interpolate the value of the unknown function corresponding to a certain x value, using Lagrange's interpolation formula from the given set of data, that is, a set of points x, f(x).
The calculator below can assist with the following:
- It finds the final Lagrange polynomial formula for a given data set.
- It shows step-by-step formula derivation.
- It interpolates the unknown function by computing the value of the Lagrange polynomial at the given x values (points of interpolation)
- It plots the data set, interpolated points, Lagrange polynomial and its basis polynomials on the chart.
First, enter the data points, one point per line, in the form x f(x), separated by spaces. If you want to interpolate the function by the Lagrange polynomial, enter the points of interpolation into the next field, just x values, separated by spaces.
By default, the calculator shows the final formula and interpolated points. If you want to see a step-by-step solution for the polynomial formula, turn on the "Show Step-By-Step Solution" option. The chart at the bottom shows the Lagrange polynomial, as well as its basis polynomials. These can be turned off.
You can also find some theory about the Lagrange polynomial below the calculator.
Let's suppose we have a set of data points for the unknown function, where no two x are the same:
Let's construct the following polynomial (called the Lagrange polynomial):
where is Lagrange basis polynomial
If you look at the formula of the basis polynomial for any j, you can find that for all points i not equal to j the basis polynomial for j is zero, and in point j the basis polynomial for j is one. That is,
which means that the Lagrange polynomial interpolates the function exactly.
Note that Lagrange's interpolation formula is susceptible to Runge's phenomenon. It is a problem of oscillation at the edges of an interval when using polynomials of high degree over a set of equidistant interpolation points. It is important to keep in mind, because it means that going to higher degrees (i.e. having more data points in the set) does not always improve the accuracy of the interpolation.
However, also note that unlike some other interpolation formulas, Lagrange’s formula does not require that the values of x should be equidistant. It is used in some techniques to mitigate the problem, like the change of interpolation points using Chebyshev nodes.