Calculus · Applications of derivatives

Interpolation: Reading Between the Lines of a Table

A table gives you \(\sin 0.5\) and \(\sin 1.0\), but you need \(\sin 0.7\). A measurement gives values every hour, but you need one at 2:20. Interpolation fills such gaps: it passes a polynomial through the known points and evaluates it in between. This post presents the two classical formulas, Newton's and Lagrange's, explains how accurate they are, and warns about the one way interpolation can go badly wrong.

1. The interpolation problem

We know the values \( y_0, y_1, \dots, y_n \) of a function \(y = f(x)\) at the points (nodes) \( x_0, x_1, \dots, x_n \). We want an approximate value at some other point \(x\). The natural idea is to find a simple function that passes through all the known points, and evaluate it instead. Polynomials are the simplest choice.

The key fact Through \(n + 1\) points with different \(x\)-coordinates passes exactly one polynomial of degree at most \(n\): two points determine a line, three points a parabola, and so on.

Why exactly one? If two such polynomials \(P\) and \(Q\) existed, their difference \(P - Q\) would be a polynomial of degree at most \(n\) with \(n + 1\) zeros (all the nodes). A nonzero polynomial of degree \(n\) has at most \(n\) zeros, so \(P - Q = 0\).

Using the polynomial between the nodes is interpolation; using it outside the range of the nodes is extrapolation, which is much less reliable.

2. Finite differences

When the nodes are equally spaced, \( x_{i+1} - x_i = h \), the polynomial can be built from simple subtractions arranged in a table.

Finite differences \[ \Delta y_0 = y_1 - y_0, \qquad \Delta^2y_0 = \Delta y_1 - \Delta y_0, \qquad \dots, \qquad \Delta^ny_0 = \Delta^{n-1}y_1 - \Delta^{n-1}y_0. \] Each column of the difference table is formed by subtracting neighbouring entries of the previous column.

Differences are the discrete version of derivatives. Since \( \frac{\Delta y}{h} \approx f'(x) \), we have \( \Delta^ky_0 \approx h^kf^{(k)}(x_0) \). In particular, for a polynomial of degree \(n\), the \(n\)-th differences are constant and the \((n + 1)\)-th are zero, just as its \(n\)-th derivative is constant. Rapidly shrinking differences tell you that a low-degree polynomial will fit the data well.

Example 1 · A difference table for \(\sin x\) Nodes \(x = 0, 0.5, 1.0, 1.5\) (\(h = 0.5\)):
\(x\)\(y = \sin x\)\(\Delta y\)\(\Delta^2y\)\(\Delta^3y\)
0.00.000000.47943−0.11738−0.08864
0.50.479430.36205−0.20602
1.00.841470.15602
1.50.99749
The top entry of each column (\(y_0, \Delta y_0, \Delta^2y_0, \Delta^3y_0\)) is all Newton's formula needs.

3. Newton's interpolation formula

Newton's (forward) interpolation formula If \(y_0, y_1, \dots, y_n\) are the values of \(y = f(x)\) at equally spaced nodes \(x_0, x_1, \dots, x_n\), \( x_{i+1} - x_i = h \), then the values at other points are approximately given by \[ y = y_0 + q\,\Delta y_0 + \frac{q(q - 1)}{2!}\Delta^2y_0 + \cdots + \frac{q(q - 1)\cdots(q - n + 1)}{n!}\Delta^ny_0, \qquad q = \frac{x - x_0}{h}. \tag{1} \]

The variable \(q\) measures the position of \(x\) in "steps": \(q = 0\) at \(x_0\), \(q = 1\) at \(x_1\), \(q = 1.4\) a little less than halfway between \(x_1\) and \(x_2\).

Why it works: the right side is a polynomial of degree \(n\) in \(q\) (and therefore in \(x\)). At \(q = 0\) it gives \(y_0\). At \(q = 1\) all terms after the second vanish (they contain the factor \(q - 1\)), leaving \( y_0 + \Delta y_0 = y_1 \). At \(q = 2\): \( y_0 + 2\Delta y_0 + \Delta^2y_0 = y_2 \), and so on. So it passes through all the nodes, and by uniqueness it is the interpolation polynomial.

The analogy with Taylor: compare with \( f(x) = f(x_0) + \frac{f'(x_0)}{1!}(x - x_0) + \frac{f''(x_0)}{2!}(x - x_0)^2 + \cdots \). Newton's formula is its discrete twin: derivatives become differences, and powers \((x - x_0)^k\) become "falling" products \(q(q - 1)\cdots(q - k + 1)\).

For \(n = 1\) the formula is \( y = y_0 + q\,\Delta y_0 \): linear interpolation, the straight line through two neighbouring points. It is what everyone does instinctively when reading a table.

Example 2 · \(\sin 0.7\) from the table \( q = \frac{0.7 - 0}{0.5} = 1.4 \). Adding the terms of (1) one by one:
DegreeAdded termApproximation
1 (linear)\(1.4\cdot 0.47943\)0.67120
2\(\frac{1.4\cdot 0.4}{2}\cdot(-0.11738)\)0.63833
3\(\frac{1.4\cdot 0.4\cdot(-0.6)}{6}\cdot(-0.08864)\)0.64329
The true value is \( \sin 0.7 = 0.64422 \). Each extra term improves the result; the cubic is off by less than \(0.001\).

4. How accurate is it?

Error of Newton's formula If \(f\) has a continuous derivative \(f^{(n+1)}\), the error of formula (1) is \[ R_n(x) = \frac{h^{n+1}}{(n + 1)!}f^{(n+1)}(\xi)\,q(q - 1)\cdots(q - n), \] where \(\xi\) lies in the smallest interval containing the nodes and the point \(x\). When the derivative is unknown, it can be estimated from the next difference: \[ R_n(x) \approx \frac{\Delta^{n+1}y_0}{(n + 1)!}\,q(q - 1)\cdots(q - n). \]

The structure is just like Lagrange's remainder in Taylor's formula (previous post): "the next term", with the derivative evaluated at an unknown point. The second form uses \( \Delta^{n+1}y_0 \approx h^{n+1}f^{(n+1)} \), so it can be computed from the table alone, which is handy when the data come from measurements and \(f\) is unknown.

Example 3 · Checking the error For the cubic in Example 2 (\(n = 3\)), \( |f^{(4)}| = |\sin x| \le 1 \), and \( q(q - 1)(q - 2)(q - 3) = 1.4\cdot 0.4\cdot(-0.6)\cdot(-1.6) = 0.5376 \): \[ |R_3| \le \frac{0.5^4}{4!}\cdot 0.5376 \approx 0.0014. \] The actual error is \(0.00092\): within the bound.

The factor \( q(q - 1)\cdots(q - n) \) explains two practical rules:

5. Lagrange's interpolation polynomial

Newton's formula (1) needs equal spacing. Lagrange's formula works for any nodes.

Lagrange's interpolation polynomial The polynomial whose graph passes through the \(n + 1\) points \( M_i(x_i, y_i) \), \( i = 0, 1, \dots, n \), is \[ P_n(x) = \frac{(x - x_1)(x - x_2)\cdots(x - x_n)}{(x_0 - x_1)(x_0 - x_2)\cdots(x_0 - x_n)}\,y_0 + \frac{(x - x_0)(x - x_2)\cdots(x - x_n)}{(x_1 - x_0)(x_1 - x_2)\cdots(x_1 - x_n)}\,y_1 + \cdots + \frac{(x - x_0)(x - x_1)\cdots(x - x_{n-1})}{(x_n - x_0)(x_n - x_1)\cdots(x_n - x_{n-1})}\,y_n. \tag{2} \]

Compactly, \( P_n(x) = \sum_{k=0}^n y_k\,L_k(x) \), where

\[ L_k(x) = \prod_{i \ne k}\frac{x - x_i}{x_k - x_i}. \]

The idea is beautifully simple. Each \(L_k\) is a polynomial of degree \(n\) built to be a "switch":

\[ L_k(x_k) = 1, \qquad L_k(x_i) = 0 \quad (i \ne k). \]

The numerator vanishes at every node except \(x_k\); the denominator is the numerator evaluated at \(x_k\), so it normalizes the value there to \(1\). Then at the node \(x_i\), the sum \( \sum y_kL_k(x_i) \) keeps only the term \(y_i\cdot 1\). Each data point is "switched on" by its own basis polynomial.

Example 4 · A parabola through three points Through \( (0, 1) \), \( (1, 3) \), \( (3, 2) \) (unequally spaced): \[ P_2(x) = 1\cdot\frac{(x - 1)(x - 3)}{(0 - 1)(0 - 3)} + 3\cdot\frac{(x - 0)(x - 3)}{(1 - 0)(1 - 3)} + 2\cdot\frac{(x - 0)(x - 1)}{(3 - 0)(3 - 1)}. \] Expanding: \( P_2(x) = -\frac56x^2 + \frac{17}{6}x + 1 \). Check: \( P_2(1) = -\frac56 + \frac{17}6 + 1 = 3 \) ✓, \( P_2(3) = -7.5 + 8.5 + 1 = 2 \) ✓.
Error of Lagrange's formula If \(f\) has a continuous \(f^{(n+1)}\) on an interval containing the nodes and \(x\), the error of formula (2) is \[ R_n(x) = \frac{f^{(n+1)}(\xi)}{(n + 1)!}(x - x_0)(x - x_1)\cdots(x - x_n), \] with \(\xi\) in the smallest interval containing \(x_0, \dots, x_n\) and \(x\).

(For equal spacing, \( x - x_i = h(q - i) \), and this becomes exactly the error of Newton's formula.)

Example 5 · \(\sqrt5\) from \(\sqrt1, \sqrt4, \sqrt9\) Nodes \(1, 4, 9\) with values \(1, 2, 3\). At \(x = 5\): \[ P_2(5) = 1\cdot\frac{(5 - 4)(5 - 9)}{(1 - 4)(1 - 9)} + 2\cdot\frac{(5 - 1)(5 - 9)}{(4 - 1)(4 - 9)} + 3\cdot\frac{(5 - 1)(5 - 4)}{(9 - 1)(9 - 4)} = -\frac16 + \frac{32}{15} + \frac{3}{10} = 2.2667. \] The true value is \(2.2361\). Linear interpolation between \(4\) and \(9\) alone would give \(2.2\). The quadratic is better, but the nodes are far apart and \(\sqrt x\) bends strongly near \(1\), so the error is still about \(0.03\).
Example 6 · An error bound Interpolate \( \sin x \) at \( 0, \frac\pi2, \pi \): the parabola is \( P_2(x) = \frac{4}{\pi^2}x(\pi - x) \). At \( x = \frac\pi4 \): \( P_2 = \frac34 = 0.75 \), while \( \sin\frac\pi4 = 0.7071 \). The bound, with \( |f'''| \le 1 \): \[ |R_2| \le \frac{1}{3!}\cdot\frac\pi4\cdot\frac\pi4\cdot\frac{3\pi}{4} = \frac{3\pi^3}{384} \approx 0.24. \] The actual error \(0.043\) is well within it. (Bounds are guarantees, not predictions; they are often pessimistic.)

6. One polynomial, two formulas

By uniqueness (Section 1), Newton's and Lagrange's formulas give the same polynomial on the same nodes. They differ only in how the polynomial is written, and that matters in practice:

Newton (forward differences)Lagrange
Nodesequally spacedarbitrary
Adding a nodeeasy: one more term, earlier terms unchangedevery basis polynomial changes
Choosing the degreeeasy: watch the differences shrinkmust be fixed in advance
Error estimatefrom the next difference \(\Delta^{n+1}y_0\)needs a bound on \(f^{(n+1)}\)
Theory, proofsless transparentvery clear structure

7. A warning: Runge's phenomenon

It seems obvious that more nodes, and so a higher degree, always give a better approximation. It is not true. In 1901 Carl Runge interpolated the innocent-looking function

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

on \([-1, 1]\) at equally spaced nodes. As the degree grows, the polynomial gets better in the middle but develops wild oscillations near the ends, and the maximum error tends to infinity.

−1 −0.5 0.5 1 2 1 f(x) P₁₀(x)
Figure 1. Runge's function \( \frac{1}{1 + 25x^2} \) (black) and its interpolation polynomial of degree 10 at 11 equally spaced nodes (red dots). Between the nodes near \(\pm1\), the polynomial swings up to almost \(2\), although the function never exceeds \(0.04\) there.

The culprit is the factor \( (x - x_0)\cdots(x - x_n) \) in the error formula: for equally spaced nodes it is enormous near the ends of the interval, and the high derivatives of Runge's function grow fast enough that nothing compensates. The remedies used in practice:

8. Summary

ConceptFormula
Finite differences\( \Delta y_0 = y_1 - y_0,\ \Delta^ky_0 = \Delta^{k-1}y_1 - \Delta^{k-1}y_0 \)
Newton's formula\( y = y_0 + q\Delta y_0 + \frac{q(q-1)}{2!}\Delta^2y_0 + \cdots,\ \ q = \frac{x - x_0}{h} \)
Newton's error\( R_n = \frac{h^{n+1}f^{(n+1)}(\xi)}{(n+1)!}q(q-1)\cdots(q-n) \approx \frac{\Delta^{n+1}y_0}{(n+1)!}q(q-1)\cdots(q-n) \)
Lagrange's polynomial\( P_n(x) = \sum y_kL_k(x),\ \ L_k(x) = \prod_{i\ne k}\frac{x - x_i}{x_k - x_i} \)
Lagrange's error\( R_n = \frac{f^{(n+1)}(\xi)}{(n+1)!}(x - x_0)\cdots(x - x_n) \)
Uniquenessone polynomial of degree \(\le n\) through \(n + 1\) points

9. Practice problems

Try each one before opening the solution. More solved problems from this topic are in Differential Calculus.

Problem 1: Make the difference table of \( y = x^3 \) at \( x = 0, 1, 2, 3, 4 \).

\(y\): \(0, 1, 8, 27, 64\); \(\Delta\): \(1, 7, 19, 37\); \(\Delta^2\): \(6, 12, 18\); \(\Delta^3\): \(6, 6\); \(\Delta^4\): \(0\). The third differences are constant, \( 6 = 3!\,h^3 \), as expected for a cubic.

Problem 2: From \(\ln 2 = 0.6931\) and \(\ln 3 = 1.0986\), estimate \(\ln 2.5\) by linear interpolation, and bound the error.

\( 0.6931 + 0.5\cdot 0.4055 = 0.8959 \). Error bound: \( |f''| = \frac1{x^2} \le \frac14 \), so \( |R_1| \le \frac{1/4}{2}\cdot|0.5\cdot(-0.5)| = 0.03125 \). Actual: \( \ln 2.5 = 0.9163 \), error \(0.0204\).

Problem 3: Find the Lagrange polynomial through \( (-1, 2) \), \( (0, 1) \), \( (1, 2) \).

\( 2\cdot\frac{x(x - 1)}{2} + 1\cdot\frac{(x + 1)(x - 1)}{-1} + 2\cdot\frac{(x + 1)x}{2} = x^2 - x - x^2 + 1 + x^2 + x = x^2 + 1 \).

Problem 4: Using Newton's formula, find the polynomial through \( (0, 1), (1, 2), (2, 5), (3, 10) \).

\(\Delta\): \(1, 3, 5\); \(\Delta^2\): \(2, 2\); \(\Delta^3\): \(0\). With \(h = 1\), \(q = x\): \( y = 1 + x + \frac{x(x - 1)}{2}\cdot 2 = x^2 + 1 \). The zero third difference shows the data lie on a parabola.

Problem 5: Show that \( L_0(x) + L_1(x) + \cdots + L_n(x) = 1 \) for all \(x\).

Interpolate the constant function \(f(x) = 1\): all \(y_k = 1\), so \( P_n = \sum L_k \). Since \(f^{(n+1)} = 0\), the error is zero: \( P_n(x) = 1 \) exactly.

Problem 6: Why is extrapolation (using the polynomial outside the nodes) risky?

The error contains \( (x - x_0)(x - x_1)\cdots(x - x_n) \), which is small between the nodes but grows like \(|x|^{n+1}\) outside them. A polynomial fitted to a few points can shoot off in any direction once it leaves their range.

Final thoughts

Interpolation answers a very practical question: what happens between the points we know? Newton's formula builds the answer from a table of differences, a discrete Taylor formula; Lagrange's formula builds it from switch-like basis polynomials, one per data point. Both produce the same unique polynomial, and both come with an error term that looks just like Taylor's remainder. Used with a few nearby points, interpolation is remarkably accurate; pushed to high degrees on equally spaced points, it can fail spectacularly. Knowing both sides is what makes it a reliable tool.

Related posts: Taylor's formula (the continuous analogue, and the form of the error) and finding roots numerically.