Lagrange interpolation calculator
Enter points (x, y) and get the unique polynomial of lowest degree that passes through all of them. The calculator works in exact fractions, shows the polynomial both expanded and in Lagrange form, and evaluates it at an x of your choice.
Runs in your browser: nothing you enter is sent anywhere.
How to use it
- Enter the points, for example
(0, 1), (1, 3), (2, 7), (3, 13).
- Optionally enter the x where you want the value.
- Read the polynomial, its value and the Lagrange form; the graph shows the curve over your data.
How it works
For points (x₁, y₁) … (xₙ, yₙ) the Lagrange basis polynomial ℓᵢ(x) is the product of (x − xⱼ) / (xᵢ − xⱼ) over all j ≠ i. The interpolating polynomial is the sum of yᵢ · ℓᵢ(x). The calculator multiplies these out with exact rational numbers and collects powers of x.
Worked example
Through (1, 1), (2, 4) and (3, 9):
P(x) = 1 · (x − 2)(x − 3) / 2 + 4 · (x − 1)(x − 3) / (−1) + 9 · (x − 1)(x − 2) / 2
Expanding: (x² − 5x + 6)/2 − 4(x² − 4x + 3) + 9(x² − 3x + 2)/2 = x². So P(x) = x², and P(2.5) = 6.25.
Tips
- Every x must be different; repeated x values have no single polynomial.
- With more than about 8 points, a fitted line or curve (regression) often describes noisy data better.
Frequently asked questions
What is Lagrange interpolation?
A way to write the one polynomial of degree at most n − 1 that passes through n points with different x. It is P(x) = Σ yᵢ · ℓᵢ(x), where each basis polynomial ℓᵢ(x) = Π (x − xⱼ) / (xᵢ − xⱼ) is 1 at xᵢ and 0 at every other point.
Why is the degree lower than I expected?
Four points usually need a cubic, but if they happen to lie on a parabola or a line, the cubic and quadratic coefficients cancel. The points (0, 1), (1, 3), (2, 7), (3, 13) all lie on x² + x + 1, so the degree is 2.
Are the coefficients rounded?
No. All arithmetic is done in exact fractions, so the polynomial goes through your points exactly. Switch to decimals if you prefer, but the fraction form is the true answer.
Can I extrapolate beyond my points?
You can evaluate at any x, but outside the range of the data the polynomial is not reliable: it is fitted only to pass through the given points, not to follow a trend.
What is the difference from linear interpolation?
Linear interpolation joins two neighbouring points with a straight line. Lagrange interpolation uses all points at once and gives one smooth polynomial.