Lagrange Interpolation Calculator

Construct the unique interpolating polynomial of degree ≤ n-1 that passes through n given data points. Evaluate at any x, visualize the polynomial curve, and get explicit coefficients.

Examples:
? Linear (0,1),(2,5)
? Quadratic (0,1),(1,2),(3,4)
? Cubic (0,0),(1,1),(2,4),(3,9)
⚠️ Runge (6 points on f(x)=1/(1+25x²))
? Sine approx (0,0),(π/2,1),(π,0)
Privacy first: All calculations are performed locally in your browser. Your data never leaves your device. The graph and polynomial are computed on the client side.

The Lagrange Interpolation Method

Lagrange interpolation is a classical technique for finding a polynomial that passes exactly through a given set of points. For n distinct points (x₀, y₀), (x₁, y₁), …, (xₙ₋₁, yₙ₋₁), there exists a unique polynomial P(x) of degree at most n-1 such that P(xᵢ) = yᵢ. The Lagrange form is expressed as:

P(x) = Σᵢ yᵢ · ℓᵢ(x), where ℓᵢ(x) = ∏ⱼ≠ᵢ (x – xⱼ)/(xᵢ – xⱼ).

This representation is numerically stable for moderate n and provides a direct construction without solving linear systems. The method is fundamental in numerical analysis, computer-aided design, and scientific computing. Our calculator uses a robust coefficient aggregation algorithm to compute the explicit polynomial coefficients, evaluate efficiently, and visualize the curve with high precision.

Mathematical Foundation & Historical Context

Developed by Joseph-Louis Lagrange in the 18th century, the interpolation polynomial underpins many areas of mathematics including finite element methods, quadrature rules (Newton-Cotes), and function approximation. The uniqueness stems from the fact that a polynomial of degree ≤ n-1 is uniquely determined by n conditions. The error term is given by P(x) - f(x) = f⁽ⁿ⁾(ξ)/n! · ∏(x - xᵢ), which highlights the importance of point distribution — equispaced nodes can lead to severe oscillations (Runge phenomenon).

Implementation Details: From Lagrange Basis to Standard Polynomial Form

Our implementation expands each Lagrange basis polynomial ℓᵢ(x) into its standard monomial form by repeatedly multiplying linear factors (x - xⱼ). The coefficients of each basis polynomial are accumulated with weight yᵢ, and the final sum yields the coefficient array [a₀, a₁, …, aₙ₋₁] such that P(x) = a₀ + a₁·x + … + aₙ₋₁·xⁿ⁻¹. This explicit coefficient representation allows fast evaluation using Horner’s method and precise rendering of the curve. The algorithm runs in O(n³) time, suitable for up to 8 points, and includes safeguards against duplicate x-coordinates.

Practical Applications

  • Signal processing: Reconstruction of continuous signals from discrete samples.
  • Computer graphics: Curve fitting and path interpolation (Bézier curves share conceptual roots).
  • Numerical integration: Gaussian quadrature and Romberg integration rely on polynomial interpolation.
  • Data science: Smoothing and approximation of experimental datasets.
  • Engineering: Finite element shape functions and empirical model building.
Case Study: Runge Phenomenon Visualization

The Runge phenomenon demonstrates that high-degree polynomial interpolation at equally spaced points can oscillate wildly near the boundaries, especially for functions like f(x)=1/(1+25x²). Our preset "Runge" example shows this instability: even with 6 points, the interpolant deviates significantly from the true function. This highlights the need for alternative approaches such as Chebyshev nodes or spline interpolation for equispaced data. Use the interactive graph to explore how adding points affects oscillation.

How To Use This Tool

  1. Add or remove points using the buttons; each point requires an x and y coordinate (real numbers).
  2. Use preset examples to quickly explore linear, quadratic, or challenging cases.
  3. The interpolating polynomial coefficients are automatically computed and displayed.
  4. Enter any x-value to evaluate P(x) instantly.
  5. The canvas shows the polynomial curve (smoothed) along with the data points.

Accuracy & Limitations

Our implementation uses double-precision arithmetic and a robust polynomial multiplication algorithm. For high-degree polynomials (≥ 8), numerical errors may increase. For more than 6 points, we recommend using Chebyshev nodes or spline interpolation to mitigate Runge's phenomenon and improve stability. The tool is optimized for educational use and small-to-medium datasets (2 to 8 points). Lagrange interpolation is ideal for exact reconstruction but can be unstable for large n due to Runge's phenomenon. When working with equispaced data beyond 6 points, consider piecewise interpolation methods.

Academic References & Authority – This tool follows the mathematical rigor of classic numerical analysis texts: Burden & Faires, "Numerical Analysis"; Quarteroni, Sacco, Saleri, "Numerical Mathematics". Lagrange interpolation formulas are derived from fundamental polynomial theory. The implementation uses explicit coefficient extraction verified against symbolic computation. Reviewed by the GetZenQuery Tech team.last reviewed March 2026

Frequently Asked Questions

The error depends on the (n)th derivative of the underlying function and the product of (x - xᵢ). If the function is smooth, error reduces as n increases, but equidistant nodes may cause divergence (Runge).

High-degree polynomials tend to oscillate between nodes, especially near endpoints (Runge phenomenon). Using Chebyshev nodes or splines can mitigate this.

No. Interpolation requires a single y for each x. Repeated x-values cause a zero denominator in Lagrange basis; the tool will show a warning.

We expand each Lagrange basis polynomial and combine them with yᵢ weights. The result is a standard coefficient array from constant term to highest power.

Yes, by construction the polynomial matches every given data point exactly (subject to floating-point rounding).
Further Learning & Advanced Topics

To deepen your understanding of polynomial interpolation and its variants, explore these resources:

These methods are essential for practical data fitting and are widely used in scientific computing, computer graphics, and engineering simulation.