What Lagrange interpolation actually does
Interpolation answers one question: you have measured or tabulated a quantity at a handful of points, and you need its value somewhere in between. Lagrange interpolation answers it by constructing a single polynomial that agrees with your data at every node you supplied, and then reading that polynomial at the point you want.
For n distinct nodes there is exactly one polynomial of degree at most n − 1 through them. That uniqueness is the whole reason the method is trustworthy: whether you build it by the Lagrange formula, by Newton's divided differences, or by solving a Vandermonde system, you get the same curve. The forms differ only in how much arithmetic they cost and how easily you can add another point later.
The word degree at most matters. Four points that happen to lie on a straight line give you a degree-1 polynomial, not a cubic with three vanishing coefficients. This calculator reports the true degree after dropping leading coefficients that come out as zero, so you can see when your data is simpler than the number of points suggests.
Interpolation is not curve fitting. A least-squares fit deliberately misses the data points to smooth out noise; an interpolating polynomial hits every one of them, noise included. If your y values carry measurement error, a fit is the honest tool and interpolation will chase the errors. Use this calculator when the tabulated values are exact - physical constants, code-book tables, published factors - or when you deliberately want the exact-through-the-points curve.
The formula, and why it has that shape
The Lagrange form writes the answer as a weighted sum of your y values:
P(x) = y₀L₀(x) + y₁L₁(x) + … + yₙ₋₁Lₙ₋₁(x)
Each weight Li(x) is built to be a switch. It equals 1 at its own node xi and 0 at every other node:
Lᵢ(x) = ∏₀₋ᵢ (x − x⫺) / (xᵢ − x⫺)
Look at the numerator. It contains a factor (x − x⫺) for every node except the i-th, so it vanishes at all of them. The denominator is that same product evaluated at xi, which forces Lᵢ(xᵢ) = 1. Substitute any node into the full sum and every term dies except one, leaving exactly the y value you supplied. That is the proof that the polynomial interpolates, and it takes one line.
Two consequences worth remembering. First, the basis values at any x always sum to 1, because interpolating the constant function 1 must return 1; the table below lets you verify that on your own data. Second, the denominators are the only place a division happens, and they are zero only if two nodes coincide - which is why repeated x values are rejected rather than approximated.
The Newton divided-difference form rewrites the same polynomial as P(x) = f[x₀] + f[x₀,x₁](x − x₀) + f[x₀,x₁,x₂](x − x₀)(x − x₁) + …, where the coefficients are the top diagonal of the difference triangle. Its advantage is incremental: add a new data point and you append one term, while the Lagrange form has to be rebuilt from scratch because every denominator changes.
Worked example: four points of a cubic
Take the four points (1, 1), (2, 8), (3, 27) and (4, 64) - the cubes of the first four integers - and interpolate at x = 2.5.
- Build the denominators. For i = 0 (node x = 1): (1−2)(1−3)(1−4) = (−1)(−2)(−3) = −6. For i = 1: (2−1)(2−3)(2−4) = (1)(−1)(−2) = 2. For i = 2: (3−1)(3−2)(3−4) = (2)(1)(−1) = −2. For i = 3: (4−1)(4−2)(4−3) = (3)(2)(1) = 6.
- Build the numerators at x = 2.5. L0: (2.5−2)(2.5−3)(2.5−4) = (0.5)(−0.5)(−1.5) = 0.375. L1: (2.5−1)(2.5−3)(2.5−4) = (1.5)(−0.5)(−1.5) = 1.125. L2: (2.5−1)(2.5−2)(2.5−4) = (1.5)(0.5)(−1.5) = −1.125. L3: (2.5−1)(2.5−2)(2.5−3) = (1.5)(0.5)(−0.5) = −0.375.
- Divide. L0 = 0.375 ÷ −6 = −0.0625; L1 = 1.125 ÷ 2 = 0.5625; L2 = −1.125 ÷ −2 = 0.5625; L3 = −0.375 ÷ 6 = −0.0625. They sum to −0.0625 + 0.5625 + 0.5625 − 0.0625 = 1, as they must.
- Weight the y values. 1(−0.0625) + 8(0.5625) + 27(0.5625) + 64(−0.0625) = −0.0625 + 4.5 + 15.1875 − 4 = 15.625.
The answer is 15.625, and you can check it instantly: four points of y = x3 determine that cubic uniquely, and 2.53 = 15.625. The expanded form the calculator prints is P(x) = x^3 - every lower coefficient cancels to zero, which is exactly the uniqueness theorem doing its job.
The divided-difference triangle for the same data reads 1, 7, 6, 1 down its top diagonal, giving P(x) = 1 + 7(x−1) + 6(x−1)(x−2) + 1(x−1)(x−2)(x−3). At x = 2.5 that is 1 + 10.5 + 6(1.5)(0.5) + (1.5)(0.5)(−0.5) = 1 + 10.5 + 4.5 − 0.375 = 15.625. Same number, different bookkeeping.
How to read the result
Trust the value most when your target sits near the middle of the node range and the nodes are close together. The classical error bound for interpolation at n nodes is
f(x) − P(x) = f⁽ⁿ⁾(ξ) / n! × (x−x₀)(x−x₁)…(x−xₙ₋₁)
for some unknown ξ in the interval. You usually cannot evaluate the derivative term, but the product term is fully under your control and it tells you most of what you need. It is smallest between the two central nodes and grows without limit outside the range - which is why extrapolation one node-spacing past the end is already risky and three spacings past is usually worthless. The calculator flags any target outside the data range for this reason.
The reported degree is a diagnostic. If you feed eleven points and get degree 10, the curve is free to wiggle ten times; if the data is smooth, that freedom shows up as oscillation between the nodes rather than as accuracy. Watch the chart: a polynomial that swings far above and below the data between the last few nodes is telling you the degree is too high for the job.
The slope output is the derivative of the interpolating polynomial at your target. It is a reasonable estimate of the underlying function's derivative near the middle of the range, and a poor one near the ends, where interpolation error grows fastest and differentiation amplifies it. If you specifically want a derivative from tabulated data, a centred difference on the two nearest nodes is usually steadier than differentiating a high-degree interpolant.
Which interpolation method to reach for
| Method | Degree of the result | Work to evaluate once | Adding a new point | Best used when |
|---|---|---|---|---|
| Linear (two nearest nodes) | 1 | O(1) | Free | Dense tables, or any table where you must not overshoot |
| Lagrange form | ≤ n − 1 | O(n2) | Rebuild every basis polynomial | One-off evaluation, hand work, proofs |
| Newton divided differences | ≤ n − 1 | O(n2) to build, O(n) after | Append one term | Data arriving incrementally, repeated evaluation |
| Barycentric Lagrange | ≤ n − 1 | O(n) after O(n2) setup | Update every weight | Many evaluations of the same fixed node set |
| Cubic spline | 3 on each sub-interval | O(n) setup, O(1) after | Re-solve the tridiagonal system | Many nodes, smooth curve wanted, no oscillation |
| Least-squares polynomial fit | Chosen by you | O(n) per evaluation | Refit | Noisy measurements, where hitting every point is wrong |
All the interpolating rows produce the same curve for the same nodes; they differ in arithmetic cost and in how gracefully they absorb a new data point.
Mistakes that produce a plausible wrong number
- Extrapolating past the last node. The polynomial is unconstrained outside the range and the highest-power term dominates immediately. A degree-6 interpolant can be off by orders of magnitude one spacing beyond the end while still looking smooth on screen.
- Feeding every point you have. More nodes means higher degree, not more accuracy. For a smooth function, three or four nodes bracketing your target usually beat twenty spread across the whole table.
- Using equally spaced nodes at high degree. Runge's function
1/(1+25x^2)on [−1, 1] is the standard counterexample: the interpolation error at the ends grows as you add equally spaced nodes. Chebyshev node spacing fixes it; equal spacing does not. - Interpolating noisy data. The curve is forced through every measurement, so scatter becomes wiggle. Fit instead.
- Repeating an x value. Two rows with the same x make a denominator zero. If you genuinely have a value and a slope at the same point, you want Hermite interpolation, which is built for repeated nodes.
- Reading the expanded coefficients too literally. Expanding a high-degree interpolant into powers of x is numerically fragile - large coefficients of opposite sign cancel. Evaluate through the basis or the Newton form when precision matters.
Where this sits among the numerical methods
Interpolation is the foundation under a surprising amount of numerical analysis. Integrate the interpolating polynomial instead of the function and you get the Newton-Cotes rules directly: fit a straight line through two nodes and integrate it and you have the trapezoidal rule; fit a parabola through three and you have Simpson's rule. Differentiate it and you get the finite-difference formulas. Invert it - interpolate x as a function of y and evaluate at y = 0 - and you have inverse interpolation, a respectable root-finder in its own right.
That last connection runs the other way too. The secant method is precisely linear inverse interpolation applied repeatedly, and Muller's method is the quadratic version. If you have a derivative available, Newton-Raphson is the faster choice; if you do not, the interpolation-based methods are what remain.
For a local approximation around a single point rather than through a set of points, the Taylor series is the counterpart: it matches many derivatives at one place, where interpolation matches one value at many places. And when the underlying relationship is known to be linear or polynomial but the data is noisy, a least-squares fit through a normal-equation solve replaces interpolation altogether.
The method is named for Joseph-Louis Lagrange, who published it in 1795, though Edward Waring had described the same construction in 1779 and Euler rediscovered it in 1783. Nothing about the formula has changed since; what changed is that barycentric rearrangements made it numerically stable enough to use at high degree, which the naive form is not.
Key terms
- Node
- One of the x values where the polynomial is forced to match your data. Nodes must be distinct.
- Basis polynomial
- The weight Li(x) attached to yi. It equals 1 at node i and 0 at every other node.
- Divided difference
f[xᵢ,x⫺] = (f⫺ − fᵢ)/(x⫺ − xᵢ), and recursively for higher orders. The top diagonal of the triangle gives the Newton form coefficients.- Runge phenomenon
- The growth of interpolation error near the ends of an interval as more equally spaced nodes are added. Named for Carl Runge, who exhibited it in 1901.
- Extrapolation
- Evaluating the polynomial outside the range of the nodes. Legal arithmetic, unreliable prediction.
