This calculator constructs the unique polynomial that passes exactly through a set of data points using the Lagrange interpolation formula. You enter sample points (x, y), choose a value of x, and the tool:
This is useful in numerical methods, physics and engineering labs, computer graphics, and for learning how polynomial interpolation works in practice.
Suppose you have n + 1 distinct data points . There exists a unique polynomial P(x) of degree at most n such that:
P(x_i) = y_i for every index i = 0, 1, …, n.
Lagrange interpolation expresses this polynomial as a sum of Lagrange basis polynomials that are constructed directly from the x-values of your data. Each basis polynomial is equal to 1 at one data point and 0 at all the others, so their weighted sum reproduces all the y-values exactly.
The interpolating polynomial is written as
P(x) = ∑i=0n yi Li(x),
where the Lagrange basis polynomials are
Li(x) = ∏j=0, j ≠ in
(x − xj)/(xi − xj).
Each Li(x) satisfies
Li(xi) = 1 and
Li(xk) = 0 for all k ≠ i, so the sum
P(x) = ∑ yiLi(x) passes exactly through all points.
The same idea in MathML form is:
The calculator implements these products numerically. For a moderate number of points this is efficient and avoids solving a separate linear system for the coefficients.
To use the Lagrange interpolation calculator effectively, follow these steps:
x,y.0,1, 1.5,2.75).P(x) = ∑ yiLi(x) and evaluates it at the chosen x.For numerical stability and interpretability, many practical problems work well with between 3 and 10 points. Very high-degree interpolating polynomials can behave unpredictably.
After running the calculator, you will typically see:
P(xeval), where xeval is the x-value you entered. If this x is equal to one of your original x-values, the result should match the corresponding y-value (up to rounding error).
You can check consistency in several ways:
Consider three data points:
We want the polynomial P(x) of degree at most 2 that passes through all three points, and we will evaluate it at x = 0.5.
In the data points field, type:
0,1 1,2 2,0
Then set the evaluation x-value to 0.5 and click Interpolate.
For three points we have indices i = 0, 1, 2:
L0(x) = (x - 1)(x - 2) / ((0 - 1)(0 - 2)) = (x - 1)(x - 2) / 2
L1(x) = (x - 0)(x - 2) / ((1 - 0)(1 - 2)) = -x(x - 2)
L2(x) = (x - 0)(x - 1) / ((2 - 0)(2 - 1)) = x(x - 1) / 2
The polynomial is then
P(x) = 1 × L0(x) + 2 × L1(x) + 0 × L2(x).
Substituting the expressions for L0 and L1 and simplifying gives:
P(x) = -½x2 + &frac32;x + 1.
Now compute:
P(0.5) = -½(0.5)2 + &frac32;(0.5) + 1
= -0.125 + 0.75 + 1
= 1.625.
The calculator will display this value as the interpolated result at x = 0.5. It will also show the symbolic polynomial, which you can compare with the analytic expression above.
Lagrange interpolation is one of several ways to construct a curve through data points. The table below contrasts it with a few common alternatives at a high level.
| Method | Main idea | Typical use cases | Key advantages | Main limitations |
|---|---|---|---|---|
| Lagrange interpolation | Single global polynomial passes exactly through all points. | Small data sets; teaching polynomial interpolation; analytical work. | Explicit formula; no need to solve linear systems; easy to evaluate for moderate n. | Can oscillate for many points; extrapolation can be unstable. |
| Newton interpolation | Builds polynomial using divided differences in an incremental form. | When points are added one at a time; numerical algorithms courses. | Efficient updates for new points; good for stepwise computation. | Still a single high-degree polynomial; similar instability for large n. |
| Piecewise linear interpolation | Connects consecutive data points with straight line segments. | Simple approximations; quick visualizations; monotone data. | Very easy to implement; no overshoot between points. | Not smooth at data points; no single global formula. |
| Cubic splines | Piecewise cubic polynomials joined with smoothness conditions. | Engineering and graphics; smooth curve fitting for many points. | Smooth, well-behaved curves; less oscillation than high-degree polynomials. | Requires solving a system; more complex than Lagrange form. |
This calculator focuses specifically on the Lagrange form, which is especially suitable for education, small sets of experimental data, and situations where you want a clear analytical expression for the interpolating polynomial.
The Lagrange interpolation implemented here rests on several important assumptions:
Keep these practical limitations in mind:
Some guidelines for using this calculator responsibly:
This Lagrange interpolation calculator can support a range of tasks:
By understanding both the capabilities and the limitations described above, you can use the Lagrange Interpolation Calculator as a precise and insightful tool for fitting polynomials to data points.