Skip to content
Numerical Calculus

Interpolation: Lagrange polynomial, Runge's phenomenon, Chebyshev nodes and splines

Existence and uniqueness of the interpolating polynomial, interpolation error, Runge's phenomenon, Chebyshev nodes, linear and cubic splines and their uses.

Often a function is known only at certain points: the values in a table, the measurements of an experiment, the samples of a signal, the characteristic curve of a sensor supplied by the manufacturer. Interpolating means building a simple function that passes exactly through those points, to estimate the values in between. In this lesson we look at the interpolating polynomial, Runge’s phenomenon which shows its limits, Chebyshev nodes and splines.

The interpolating polynomial

Given n + 1 points (x_0, y_0), \dots, (x_n, y_n) with distinct abscissas, there is exactly one polynomial of degree at most n through all of them.

Proof of uniqueness. If two polynomials p and q of degree at most n pass through the same n + 1 points, the difference p - q has degree at most n and vanishes at n + 1 distinct points. A non-zero polynomial of degree n has at most n roots, so p - q = 0.

The Lagrange form. Build the basis polynomials

    \[ \ell_i(x) = \prod_{j \ne i}\frac{x - x_j}{x_i - x_j} \]

which equal 1 at x_i and 0 at every other node. Then

    \[ p_n(x) = \sum_{i=0}^{n}y_i\,\ell_i(x) \]

passes through all the points. Example: for (0, 1), (1, 3), (2, 7) one gets p(x) = x^2 + x + 1. The Lagrange form is elegant for proofs; for calculations the Newton form with divided differences is used, which lets you add a point without recomputing everything.

The interpolation error

If f has n + 1 continuous derivatives, for every x there is \xi in the interval such that

    \[ f(x) - p_n(x) = \frac{f^{(n+1)}(\xi)}{(n + 1)!}\,\prod_{i=0}^{n}(x - x_i) \]

The error depends on two factors: how “smooth” the function is (the high-order derivative) and how the nodes are spread (the product).

Runge’s phenomenon

It seems natural that more points always give a better interpolation. They do not. In 1901 Runge studied the function

    \[ f(x) = \frac{1}{1 + 25x^2},\qquad x\in[-1, 1] \]

perfectly smooth, and interpolated it at equally spaced nodes.

Interpolation of Runge's function with equally spaced nodes and with Chebyshev nodes
Left: with 11 equally spaced nodes the interpolating polynomial (red) oscillates wildly near the ends. Right: with 11 Chebyshev nodes, denser towards the ends, the polynomial (green) follows the function (blue) closely.

With equally spaced nodes, as the degree rises the error near the ends grows without limit: with 21 nodes the polynomial reaches values above 50, while the function stays between 0 and 1. The cause is the product \prod(x - x_i), which with equally spaced nodes is much larger near the ends than in the middle. (The deep reason is complex, in the sense of complex numbers: f has poles at \pm i/5, close to the interval.)

The practical lesson: do not use high-degree polynomials on equally spaced nodes. It is the same reason a degree-10 polynomial fit to experimental data produces curves with absurd wiggles between the points.

Chebyshev nodes

If the nodes can be chosen, it pays to cluster them towards the ends. The Chebyshev nodes on [-1, 1] are

    \[ x_i = \cos\frac{(2i + 1)\pi}{2(n + 1)},\qquad i = 0, \dots, n \]

the projections onto the axis of equally spaced points on a semicircle. They make the product \prod|x - x_i| as small as possible (at most 2^{-n}), and with them the interpolation of smooth functions always converges. It is the principle numerical libraries use to approximate mathematical functions.

Splines

The most used alternative in practice is to interpolate piecewise: a low-degree polynomial between each pair of nodes, joined smoothly.

  • Piecewise linear: the points are joined with segments. Simple and free of oscillations, but with corners. It is what a spreadsheet does with a line chart, and a lookup table in a microcontroller.
  • Cubic spline: between two nodes a third-degree polynomial, with values, first derivatives and second derivatives continuous at the nodes. It is the “smoothest” curve through the points: it minimises the integral of the squared second derivative, that is the bending energy of an elastic strip forced through the points. This is exactly where the name comes from: the spline was the flexible wooden strip that ship draughtsmen held with weights to draw hull curves.

The coefficients are found by solving a tridiagonal linear system, which takes O(n) operations. Splines do not suffer from Runge’s phenomenon, and with spacing h the error is proportional to h^4.

Applications. Font outlines (TrueType uses quadratic Bézier curves, PostScript and OpenType cubic ones), the paths of robots and CNC machines, linearising sensors such as thermocouples and thermistors from the manufacturer’s tables, resampling audio and images.

Interpolation and approximation

Interpolation makes sense when the data are exact. If they are noisy measurements, forcing the curve through every point means following the noise too. In that case one looks for a simple curve that passes close to the points overall: least squares approximation, the topic of the next lesson.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x