Calculator · Engineering Mathematics

Lagrange Interpolation Calculator

Pass one polynomial through every data point and read its value anywhere. There is exactly one such polynomial of degree at most n − 1, and it is global: every point influences every value.

Data points

5 of at most 32 points. Duplicate x values are refused, never merged; unsorted points are sorted by x before use.

Query

Results

Estimate y(2.5)6.25
MethodLagrange
StatusInterpolation — inside the data span
Data points5
Data span[0, 4]
Polynomial degree4

Data and interpolating polynomial

Every data point, the single interpolating polynomial through them and the target. The curve is drawn as a dense polyline with no smoothing, so any oscillation you see is the polynomial's own.

Continue

Open in Interpolation Lab

The dataset and the target continue into the Lab with Lagrange enabled. No reference function is carried over, because this calculator does not have one.

Assumptions & validity

  • · At least 2 and at most 32 points, the documented browser-safety cap. A larger dataset is refused, never truncated.
  • · All abscissas must be distinct; duplicate x values are rejected and never merged.
  • · All coordinates must be finite.
  • · Unsorted points are sorted by x before use; the polynomial itself does not depend on the order.
  • · The interpolant passes through every point exactly, which says nothing about its behaviour between them.
  • · Outside the data span the polynomial is extrapolated and the result is labelled as such.
  • · No error estimate is produced unless you are willing to assume a bound on the nth derivative of the underlying function; none is assumed here.

Technical reference

Lagrange form: p(x) = Σⱼ yⱼ Lⱼ(x), Lⱼ(x) = Πₖ≠ⱼ (x − xₖ)/(xⱼ − xₖ)

Barycentric weights: wⱼ = 1 / Πₖ≠ⱼ (xⱼ − xₖ)

Second barycentric form (used here): p(x) = Σⱼ [wⱼ/(x − xⱼ)] yⱼ ⁄ Σⱼ [wⱼ/(x − xⱼ)]

Remainder for f ∈ Cⁿ: f(x) − p(x) = f⁽ⁿ⁾(ξ)/n! · Πⱼ (x − xⱼ)

n
number of data points
p
the unique interpolating polynomial of degree ≤ n − 1
Lⱼ
jth Lagrange basis polynomial; 1 at xⱼ and 0 at every other node
wⱼ
barycentric weight of node j
ξ
an unknown point in the interval spanned by x and the nodes

Through n points with distinct abscissas there is exactly ONE polynomial of degree at most n − 1. Newton's divided differences, the Lagrange form and a Vandermonde solve all produce that same polynomial; only the arithmetic differs.

The Lagrange form above is the definition and is what the formula means. It is not what this page evaluates: the second barycentric form gives the identical polynomial with far less cancellation and O(n) work per query, so the safer equivalent is used.

A query exactly on a node returns that node's stored ordinate directly; the barycentric quotient is 0/0 there and the interpolation condition already fixes the answer.

The interpolant is GLOBAL. Moving one data point changes the curve everywhere, unlike a piecewise method where the change stays local.

High degree on equally spaced nodes produces the Runge phenomenon: the polynomial passes through every point yet swings wildly between them near the ends of the interval. Adding more equally spaced points makes it worse, not better.

The remainder term exists only if the underlying function is n times continuously differentiable. For measured data that assumption is usually unavailable, so no error figure is shown.

Extrapolation with a polynomial is the least reliable thing on this page: outside the nodes the product term grows quickly and the value is unsupported by the data.

Related tools