# Lagrange polynomial calculator

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

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 certain *x* value, using Lagrange's interpolation formula from the given set of data, that is, set of points *x*, *f(x)*.

The calculator below can assist with the following:

- It finds 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.

### 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 Lagrange polynomial, enter the points of interpolation into the next field, just *x* values, separated by spaces.

By default calculator shows the final formula and interpolated points. If you want to see step by step solution for polynomial formula, turn on "Show Step-By-Step Solution" option. 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 Lagrange polynomial below the calculator.

### Lagrange polynomial

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

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

where is Lagrange basis polynomial

If you look at the formula of 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,

and

which means that 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 an accuracy of the interpolation.

However, also note that unlike some other interpolation formulas, Lagrange’s interpolation formula does not require that the values of x should be equidistant. It is used in some techniques to mitigate the problem, like change of interpolation points using Chebyshev nodes.

## Comments