Lagrange Interpolation
Edit interpolation nodes and an evaluation point to connect Lagrange basis weights, exact nodal interpolation and the limits of extrapolation.
By Riano · Published · Updated · Report a correction
Lagrange Interpolation: Constructing Polynomials from Points
Lagrange interpolation provides a direct way to find the unique polynomial of lowest degree that passes through a given set of data points. For n points, the resulting polynomial has a degree of at most n - 1.
The Lagrange Basis Polynomials
The interpolation polynomial p(x) is constructed as a linear combination of Lagrange basis polynomials, Li(x). Each basis polynomial is designed to equal 1 at its corresponding node xi and 0 at all other nodes xj (where j ≠ i).
The formula for the i-th basis polynomial is the product of (x - xj) / (xi - xj) for all j ≠ i. The full interpolating polynomial is simply the sum of yi × Li(x) across all points.
Worked example: Quadratic interpolation
Let's interpolate a quadratic polynomial through the nodes (-1, 1), (0, 0), and (1, 1). This is the "Quadratic" preset.
- Calculate L0(x) for x0 = -1:
L0(x) = (x - 0) / (-1 - 0) × (x - 1) / (-1 - 1) = x(x - 1) / 2 = (x2 - x) / 2 - Calculate L1(x) for x1 = 0:
L1(x) = (x - (-1)) / (0 - (-1)) × (x - 1) / (0 - 1) = (x + 1)(x - 1) / -1 = 1 - x2 - Calculate L2(x) for x2 = 1:
L2(x) = (x - (-1)) / (1 - (-1)) × (x - 0) / (1 - 0) = (x + 1)x / 2 = (x2 + x) / 2 - Multiply each by its corresponding y-value and sum:
p(x) = 1 × L0(x) + 0 × L1(x) + 1 × L2(x)
p(x) = (x2 - x) / 2 + 0 + (x2 + x) / 2 = x2
To evaluate this interpolant at x = 0.5:
L0(0.5) = (0.25 - 0.5) / 2 = -0.125 (-1/8)
L1(0.5) = 1 - 0.25 = 0.75 (3/4)
L2(0.5) = (0.25 + 0.5) / 2 = 0.375 (3/8)
The sum of these basis weights is -1/8 + 6/8 + 3/8 = 1.
p(0.5) = 1 × (-1/8) + 0 × (3/4) + 1 × (3/8) = 2/8 = 1/4 (0.25).
Verify the interpolation with the module
Open Lagrange Interpolation to explore how moving points affects the global polynomial and local basis weights.
- Select the Quadratic preset. The nodes are (-1, 1), (0, 0), and (1, 1). Set the evaluation point to 0.5. Verify the basis weights are exactly -0.1250, 0.7500, and 0.3750, summing to 1.0000, and p(0.5) = 0.2500.
- Move the evaluation point precisely to one of the nodes, for example x = 1.00. Notice that the weight for L2 becomes 1.0000 and all other weights become 0.0000, yielding p(1.00) = 1.0000 exactly. This demonstrates that Lagrange polynomials perfectly interpolate the given nodes.
- Switch to the Linear preset with nodes (0, 1) and (2, 5). The resulting polynomial is p(x) = 1 + 2x. Set the evaluation point to 1 and verify p(1) = 3.0000.
- Switch to the Constant preset. Every interpolated value across the domain is 2. Evaluating outside the node interval (e.g., x < -1 or x > 1) is correctly labeled as extrapolation.
Limitations and Runge's Phenomenon
While Lagrange interpolation guarantees finding a polynomial that passes through all points, it does not guarantee a good approximation between those points, especially for higher degrees with uniformly spaced nodes. This severe oscillation at the edges of an interval is known as Runge's phenomenon.
Evaluating the polynomial outside the range of the given nodes is called extrapolation. As seen in the interface, extrapolation is explicitly labeled. High-degree polynomials can diverge wildly outside the interpolated interval, so an extrapolated value does not imply a guaranteed or safe approximation error.
Mathematically, the formula breaks down if two nodes share the same x-coordinate, which implies division by zero when calculating basis polynomials. The module explicitly rejects duplicate or near-coincident x values (separations below 1e-6) rather than fabricating a unique polynomial, avoiding NaN or Infinity results.
The plot uses a fixed −6 to 6 window on each axis; large interpolant values may leave the view while their numerical results remain visible. Drag the canvas to pan and use Reset view to restore the origin. Colored curves show the contributions yiLi(x), not the unweighted basis functions. Near-coincident nodes are rejected below a separation of 1e-6; even accepted nodes may amplify floating-point error and do not guarantee a reliable extrapolation.
Primary References
For a formal definition of Lagrange interpolation and the remainder term for interpolation error, refer to the Digital Library of Mathematical Functions: NIST DLMF: Polynomial Interpolation. This section supports the construction of the basis polynomials used in this interactive module.
Experience it interactively
Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Lagrange Interpolation module.
Try Lagrange Interpolation on Riano →