Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

The Interpolation Problem

Problem: 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), find a polynomial p(x)p(x) such that:

p(xi)=yifor i=0,1,,np(x_i) = y_i \quad \text{for } i = 0, 1, \ldots, n
Proof 1

Existence: The Lagrange form (below) explicitly constructs such a polynomial.

Uniqueness: Suppose p(x)p(x) and q(x)q(x) are both polynomials of degree at most nn interpolating the same data. Consider the difference d(x)=p(x)q(x)d(x) = p(x) - q(x).

  • d(x)d(x) is a polynomial of degree at most nn

  • d(xi)=p(xi)q(xi)=yiyi=0d(x_i) = p(x_i) - q(x_i) = y_i - y_i = 0 for all i=0,1,,ni = 0, 1, \ldots, n

So d(x)d(x) has n+1n+1 roots. But a nonzero polynomial of degree nn can have at most nn roots. Therefore d(x)0d(x) \equiv 0, which means p(x)=q(x)p(x) = q(x).

Lagrange Basis Polynomials

For nodes x0,x1,,xnx_0, x_1, \ldots, x_n, define the Lagrange basis polynomial:

Lj(x)=i=0,ijnxxixjxiL_j(x) = \prod_{i=0, i \neq j}^{n} \frac{x - x_i}{x_j - x_i}

Key property:

Lj(xi)={1if i=j0if ijL_j(x_i) = \begin{cases} 1 & \text{if } i = j \\ 0 & \text{if } i \neq j \end{cases}

The interpolating polynomial is then:

p(x)=j=0nyjLj(x)p(x) = \sum_{j=0}^{n} y_j L_j(x)

Barycentric Interpolation

Can we do better? Yes—by algebraically reorganizing the Lagrange formula, we obtain the barycentric form, which resolves all three issues while computing the same polynomial.

The Node Polynomial

Define the node polynomial:

(x)=k=0n(xxk)=(xx0)(xx1)(xxn)\ell(x) = \prod_{k=0}^{n} (x - x_k) = (x - x_0)(x - x_1) \cdots (x - x_n)

Its derivative at a node xjx_j is:

(xj)=kj(xjxk)\ell'(x_j) = \prod_{k \neq j} (x_j - x_k)

This lets us rewrite the Lagrange basis as:

Lj(x)=(x)(xj)(xxj)L_j(x) = \frac{\ell(x)}{\ell'(x_j)(x - x_j)}

Barycentric Weights

Define the barycentric weights:

λj=1(xj)=1kj(xjxk)\lambda_j = \frac{1}{\ell'(x_j)} = \frac{1}{\prod_{k \neq j} (x_j - x_k)}

Then the Lagrange basis becomes:

Lj(x)=(x)λjxxjL_j(x) = \ell(x) \cdot \frac{\lambda_j}{x - x_j}

First Barycentric Formula

Substituting into the interpolant gives the first barycentric formula:

Once the weights λj\lambda_j are known (computed once in O(n2)O(n^2) time), evaluating p(x)p(x) costs only O(n)O(n).

Second Barycentric Formula

An even more elegant formula comes from the identity j=0nLj(x)=1\sum_{j=0}^{n} L_j(x) = 1 (the Lagrange polynomials form a partition of unity—they interpolate the constant function 1).

Dividing the interpolant by this identity:

Why Lj(x)=1\sum L_j(x) = 1?

The function g(x)=1g(x) = 1 (constant) is interpolated by itself. Since g(xj)=1g(x_j) = 1 for all jj:

1=j=0n1Lj(x)=j=0nLj(x)1 = \sum_{j=0}^{n} 1 \cdot L_j(x) = \sum_{j=0}^{n} L_j(x)

This follows from the uniqueness of polynomial interpolation.

Advantages

  1. O(n)O(n) per evaluation after O(n2)O(n^2) preprocessing for weights

  2. Numerically stable even for large nn

  3. Adding a point only requires updating weights

Implementation

def bary_weights(x):
    """Compute barycentric weights for nodes x."""
    n = len(x)
    w = np.ones(n)
    for j in range(n):
        for i in range(n):
            if i != j:
                w[j] /= (x[j] - x[i])
    return w

def bary_interp(xeval, x, y, w):
    """Evaluate interpolant at xeval using barycentric formula."""
    # Handle evaluation at nodes
    for j, xj in enumerate(x):
        if np.isclose(xeval, xj):
            return y[j]

    terms = w / (xeval - x)
    return np.dot(terms, y) / np.sum(terms)

Chebyshev Points and Barycentric Weights

For Chebyshev points, the barycentric weights have a remarkably simple closed form:

This makes Chebyshev interpolation especially efficient—no O(n2)O(n^2) weight computation needed!

def cheb_bary_weights(n):
    """Barycentric weights for Chebyshev points."""
    w = np.ones(n+1)
    w[0] = 0.5
    w[-1] = 0.5
    w[1::2] *= -1
    return w

Numerical Stability

The two barycentric formulas have different stability properties. The following results are due to Higham (2004).

Backward Stability of the First Formula

Forward Stability of the Second Formula

Comparison

FormulaStability TypeBest For
First (modified Lagrange)Backward stableExtrapolation, any nodes
Second (barycentric)Forward stableInterpolation with good nodes

Why Scale Invariance Matters

The second barycentric formula is scale invariant: we can multiply all weights by any nonzero constant without changing the result:

jcλjxxjfjjcλjxxj=jλjxxjfjjλjxxj\frac{\sum_j \frac{c\lambda_j}{x - x_j} f_j}{\sum_j \frac{c\lambda_j}{x - x_j}} = \frac{\sum_j \frac{\lambda_j}{x - x_j} f_j}{\sum_j \frac{\lambda_j}{x - x_j}}

This means we can rescale weights to avoid overflow, which is critical for large nn.

Warning: Equispaced Points

For equispaced points, the weights grow like:

λj2nn!(nj)|\lambda_j| \sim \frac{2^n}{n!} \binom{n}{j}

This grows exponentially, making polynomial interpolation through equispaced points numerically unstable—even with the barycentric formula. This is separate from (but compounds) Runge’s phenomenon.

Runge’s Phenomenon: A Warning

Consider f(x)=11+25x2f(x) = \frac{1}{1 + 25x^2} on [1,1][-1, 1].

Runge’s phenomenon: Polynomial interpolation of f(x) = 1/(1+25x^2) through equally spaced nodes. As the degree increases, the interpolant develops large oscillations near the boundaries, despite the function being smooth.

Runge’s phenomenon: Polynomial interpolation of f(x)=1/(1+25x2)f(x) = 1/(1+25x^2) through equally spaced nodes. As the degree increases, the interpolant develops large oscillations near the boundaries, despite the function being smooth.

Interpolation error comparison: (Left) Equidistant points cause error to grow exponentially with n. (Center) Chebyshev points cluster near endpoints. (Right) Chebyshev interpolation error decreases exponentially—the hallmark of spectral accuracy.

Interpolation error comparison: (Left) Equidistant points cause error to grow exponentially with nn. (Center) Chebyshev points cluster near endpoints. (Right) Chebyshev interpolation error decreases exponentially—the hallmark of spectral accuracy.

NodesError as nn \to \infty
Equally spacedGrows without bound
ChebyshevDecreases exponentially
# Equally spaced: error GROWS
x_eq = np.linspace(-1, 1, n)
f_eq = 1/(1 + 25*x_eq**2)
# Interpolant oscillates wildly near boundaries!

# Chebyshev: error DECREASES
x_cheb = np.cos(np.pi * np.arange(n) / (n-1))
f_cheb = 1/(1 + 25*x_cheb**2)
# Smooth, accurate approximation

The lesson: node placement matters. Chebyshev nodes cluster near the endpoints, exactly where equally spaced nodes cause trouble.

Use barycentric interpolation. It’s the standard in modern software (Chebfun, etc.).

References

References
  1. Higham, N. J. (2004). The numerical stability of barycentric Lagrange interpolation. IMA Journal of Numerical Analysis, 24(4), 547–556. 10.1093/imanum/24.4.547
  2. Berrut, J.-P., & Trefethen, L. N. (2004). Barycentric Lagrange interpolation. SIAM Review, 46(3), 501–517. 10.1137/S0036144502417715
  3. Webb, M., Trefethen, L. N., & Gonnet, P. (2012). Stability of barycentric interpolation formulas for extrapolation. SIAM Journal on Scientific Computing, 34(6), A3009–A3015. 10.1137/110848797