Lagrange polynomial calculator

This online calculator builds Lagrange polynomial for a given set of points, shows a step-by-step solution and plots Lagrange polynomial as well as its basis polynomials on a chart. Also, it can interpolate additional points, if given

This page exists due to the efforts of the following people:

Timur

Timur

Karen Luckhurst

Created: 2020-04-13 07:08:40, Last updated: 2020-11-09 11:51:02

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:

  1. It finds the final Lagrange polynomial formula for a given data set.
  2. It shows step-by-step formula derivation.
  3. It interpolates the unknown function by computing the value of the Lagrange polynomial at the given x values (points of interpolation)
  4. It plots the data set, interpolated points, Lagrange polynomial and its basis polynomials on the chart.

Usage

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.

PLANETCALC, Lagrange polynomial calculator

Lagrange polynomial calculator

Digits after the decimal point: 2
Lagrange Polynomial
 
The file is very large. Browser slowdown may occur during loading and creation.
The file is very large. Browser slowdown may occur during loading and creation.
Lagrange Polynomial
The file is very large. Browser slowdown may occur during loading and creation.

Lagrange polynomial

Let's suppose we have a set of data points for the unknown function, where no two x are the same:

(x_{0},y_{0}),\ldots ,(x_{j},y_{j}),\ldots ,(x_{k},y_{k})

Let's construct the following polynomial (called the Lagrange polynomial):

L(x):=\sum _{j=0}^{k}y_{j}\ell _{j}(x)

where \ell _{j}(x) is Lagrange basis polynomial

\ell _{j}(x):=\prod _{\begin{smallmatrix}0\leq m\leq k\\m\neq j\end{smallmatrix}}{\frac {x-x_{m}}{x_{j}-x_{m}}}={\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})}}

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,

y_{j}\ell _{j}(x_{j})=y_{j} \cdot 1=y_{j}

and

L(x_{j})=y_{j}+0+0+\dots +0=y_{j}

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.

URL copied to clipboard
PLANETCALC, Lagrange polynomial calculator

Comments