Lagrange Interpolation Visualization

Interactive visualization of Lagrange interpolation showing how polynomials pass through given points using basis polynomials and mathematical interpolation

By Mohamed Habib JaouadiJanuary 7, 2025
#mathematics
#interpolation
#polynomials
#numerical-analysis
#interactive
#lagrange
#easter-egg

Lagrange interpolation is a method for finding a polynomial that passes through a given set of points. This interactive visualization demonstrates how the Lagrange interpolating polynomial is constructed using basis polynomials and how it perfectly fits through all the given data points.

Mathematical Background

Given n+1n+1 distinct points (x0,y0),(x1,y1),,(xn,yn)(x_0, y_0), (x_1, y_1), \ldots, (x_n, y_n), the Lagrange interpolating polynomial P(x)P(x) is defined as:

P(x)=i=0nyiLi(x)P(x) = \sum_{i=0}^{n} y_i \cdot L_i(x)

Where Li(x)L_i(x) are the Lagrange basis polynomials:

Li(x)=j=0jinxxjxixjL_i(x) = \prod_{\substack{j=0 \\ j \neq i}}^{n} \frac{x - x_j}{x_i - x_j}

Explore how Lagrange interpolation constructs a polynomial that passes through any set of points. Adjust points, view basis polynomials, and see the mathematical beauty in action.

Lagrange Interpolation
4 Points
Degree 3
xy(1.0, 2.0)(3.0, 1.0)(5.0, 4.0)(7.0, 3.0)
Point 1
Point 2
Point 3
Point 4
Current Lagrange Polynomial

P(x) = Σ yᵢ · Lᵢ(x)

L₍0₎(x) = 2.00 × (x - 3.0) / (1.0 - 3.0) (x - 5.0) / (1.0 - 5.0) (x - 7.0) / (1.0 - 7.0)
L₍1₎(x) = 1.00 × (x - 1.0) / (3.0 - 1.0) (x - 5.0) / (3.0 - 5.0) (x - 7.0) / (3.0 - 7.0)
L₍2₎(x) = 4.00 × (x - 1.0) / (5.0 - 1.0) (x - 3.0) / (5.0 - 3.0) (x - 7.0) / (5.0 - 7.0)
L₍3₎(x) = 3.00 × (x - 1.0) / (7.0 - 1.0) (x - 3.0) / (7.0 - 3.0) (x - 5.0) / (7.0 - 5.0)

Properties: This polynomial has degree 3 and passes exactly through all 4 points. Each basis polynomial Lᵢ(x) equals 1 at point i and 0 at all other points.