TExcelTAD
Home › Numerical Methods › The Runge Phenomenon and Chebyshev Points

Runge's Phenomenon and Chebyshev Points

It seems natural that interpolating at more equally spaced points should give a better approximation. For many perfectly smooth functions it does the opposite: the interpolant oscillates wildly near the ends of the interval, and the error grows without bound. This is Runge's phenomenon. The cure is to cluster the points near the ends, using Chebyshev points.

Runge's example

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

python · try it yourself
import numpy as np
from scipy.interpolate import BarycentricInterpolator

f = lambda x: 1 / (1 + 25 * x**2)
xx = np.linspace(-1, 1, 2001)
print(" n   equispaced error   Chebyshev error")
for n in (5, 10, 20, 40):
    t_eq = np.linspace(-1, 1, n + 1)
    t_ch = -np.cos(np.pi * np.arange(n + 1) / n)          # Chebyshev points
    e_eq = np.max(np.abs(BarycentricInterpolator(t_eq, f(t_eq))(xx) - f(xx)))
    e_ch = np.max(np.abs(BarycentricInterpolator(t_ch, f(t_ch))(xx) - f(xx)))
    print(f"{n:2d}   {e_eq:16.3e}   {e_ch:15.3e}")
 n   equispaced error   Chebyshev error
 5          4.327e-01         6.386e-01
10          1.916e+00         1.322e-01
20          5.982e+01         1.774e-02
40          1.046e+05         3.399e-04

With equally spaced points the error grows exponentially (to about 10510^5 at n=40n = 40); with Chebyshev points it decreases steadily.

Why: the node polynomial

The error formula from Polynomial Interpolation contains Φ(x)=∏i=0n(x−ti)\Phi(x) = \prod_{i=0}^{n}(x - t_i). For equally spaced points ∣Φ∣\lvert\Phi\rvert is far larger near the ends than in the middle. Chebyshev points make ∣Φ∣\lvert\Phi\rvert as uniform as possible:

python · try it yourself
import numpy as np

n = 16
xx = np.linspace(-1, 1, 4001)
for name, t in (("equispaced", np.linspace(-1, 1, n + 1)), ("Chebyshev ", -np.cos(np.pi * np.arange(n + 1) / n))):
    Phi = np.prod(xx[:, None] - t[None, :], axis=1)
    middle = np.max(np.abs(Phi[np.abs(xx) < 0.2]))
    print(f"{name}: max |Phi| = {np.max(np.abs(Phi)):.2e}, max near the middle = {middle:.2e}")
equispaced: max |Phi| = 9.43e-04, max near the middle = 3.02e-07
Chebyshev : max |Phi| = 3.04e-05, max near the middle = 3.04e-05

Chebyshev points

The Chebyshev points (of the second kind) are the projections onto the xx-axis of equally spaced points on the unit circle:

tj=−cos⁡(jπn),j=0,1,…,n.t_j = -\cos\left(\frac{j\pi}{n}\right), \qquad j = 0, 1, \ldots, n.

They cluster near ±1\pm 1 with density proportional to 11−x2\frac{1}{\sqrt{1 - x^2}}. For any interval [a,b][a, b] map them linearly. Their barycentric weights have a closed form, wj=(−1)jw_j = (-1)^j (halved at the ends), so evaluation is fast and stable.

Convergence rates

For Chebyshev interpolation:

  • If ff has kk derivatives (the kk-th of bounded variation), the error is O(n−k)O(n^{-k}): algebraic convergence.
  • If ff is analytic in an ellipse around [−1,1][-1, 1], the error is O(ρ−n)O(\rho^{-n}) for some ρ>1\rho > 1: spectral (geometric) convergence. Runge's function has poles at ±i5\pm\frac{i}{5}, which limits ρ\rho to about 1.221.22.
  • Entire functions like exe^x converge faster than any geometric rate.
python · try it yourself
import numpy as np
from scipy.interpolate import BarycentricInterpolator

xx = np.linspace(-1, 1, 2001)
funcs = {"exp(x)": np.exp, "|x|^3": lambda x: np.abs(x) ** 3, "Runge": lambda x: 1 / (1 + 25 * x**2)}
for name, f in funcs.items():
    errs = []
    for n in (8, 16, 32, 64):
        t = -np.cos(np.pi * np.arange(n + 1) / n)
        errs.append(np.max(np.abs(BarycentricInterpolator(t, f(t))(xx) - f(xx))))
    print(f"{name:7s}:", "  ".join(f"{e:.1e}" if e > 1e-13 else " <1e-13" for e in errs))   # below 1e-13 is rounding noise
exp(x) : 2.2e-08   <1e-13   <1e-13   <1e-13
|x|^3  : 2.1e-03  2.6e-04  3.3e-05  4.1e-06
Runge  : 2.0e-01  3.7e-02  1.6e-03  2.9e-06

In software

  • numpy.polynomial.chebyshev.chebinterpolate(f, deg) builds a Chebyshev series interpolant; Chebyshev.fit does least squares in that basis.
  • Spectral methods for PDEs, and libraries like Chebfun, rely on Chebyshev interpolation to get 15-digit accuracy with modest nn.

Exercises

Exercise 1: The points

List the Chebyshev points for n=4n = 4.

Answer

−1,−22,0,22,1-1, -\frac{\sqrt{2}}{2}, 0, \frac{\sqrt{2}}{2}, 1.

Solution

−cos⁡(jπ/4)-\cos(j\pi/4) for j=0,…,4j = 0, \ldots, 4: −1,−0.7071,0,0.7071,1-1, -0.7071, 0, 0.7071, 1.

Exercise 2: Map to an interval

Map the Chebyshev points to [0,10][0, 10].

Answer

xj=5+5tjx_j = 5 + 5t_j.

Solution

The affine map x=a+b2+b−a2tx = \frac{a + b}{2} + \frac{b - a}{2}t sends [−1,1][-1, 1] to [a,b][a, b].

Exercise 3: Degree needed (code)

Find the smallest nn for which Chebyshev interpolation of sin⁡(10x)\sin(10x) on [−1,1][-1, 1] has maximum error below 10−1010^{-10}.

Answer

n=27n = 27.

Solution
python · try it yourself
import numpy as np
from scipy.interpolate import BarycentricInterpolator
xx = np.linspace(-1, 1, 3001); f = lambda x: np.sin(10 * x)
for n in range(5, 80):
    t = -np.cos(np.pi * np.arange(n + 1) / n)
    if np.max(np.abs(BarycentricInterpolator(t, f(t))(xx) - f(xx))) < 1e-10:
        print("n =", n); break
n = 27

Test yourself

Runge's phenomenon is caused by…

  1. rounding error
  2. interpolating at equally spaced points with high degree
  3. using Chebyshev points
  4. discontinuous functions only

Chebyshev points cluster…

  1. in the middle
  2. near the endpoints
  3. uniformly
  4. randomly

For an analytic function, Chebyshev interpolation error decreases…

  1. like 1/n1/n
  2. geometrically, like ρ−n\rho^{-n}
  3. not at all
  4. like 1/n21/n^2