A1311 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A13 · Lesson 11 · Polynomial interpolation

A curve through the points, and where it goes wrong between them

A thermistor's datasheet gives resistance at every 5 °C; your firmware needs it at 23.7 °C. A sine table in a synthesizer has 256 entries; the phase lands between them. A sample-rate converter needs the signal halfway between samples. Each time, you fit a polynomial through nearby points and evaluate it between them. Low-degree pieces work beautifully. One high-degree polynomial through many equally spaced points can fail spectacularly, swinging wildly near the ends; the fix is to choose the points, clustering them toward the ends as the Chebyshev nodes do.

  • The black curve is Runge's function. The orange curve is the polynomial through n + 1 equally spaced points; the dashed one goes through n + 1 Chebyshev points, crowded toward ±1.
  • At n = 4 both are rough. Raise n to 8 and 12: the equally spaced interpolant gets worse near the ends (its largest error grows to 3.7), while the Chebyshev one gets steadily better.
  • More points only help if they're in the right places.

Predict

A 256-entry sine table is read with linear interpolation between entries. About how large is the worst error, for a sine of amplitude 1?

Name it

The interpolating polynomial

Through n + 1 points (xi,yi) with distinct xi there's exactly one polynomial of degree at most n. In Lagrange form

p(x)=∑i=0nyiLi(x),Li(x)=∏j≠ix−xjxi−xj

and in Newton form, built from divided differences f[xi]=yi, f[xi,…,xi+k]=f[xi+1,…,xi+k]−f[xi,…,xi+k−1]xi+k−xi:

p(x)=f[x0]+f[x0,x1](x−x0)+f[x0,x1,x2](x−x0)(x−x1)+⋯

In practice use the barycentric form of Lagrange, which is stable and costs O(n) per evaluation. Never solve the Vandermonde system for the coefficients: its condition number grows exponentially with n.

The error

f(x)−p(x)=f(n+1)(ξ)(n+1)!∏i=0n(x−xi)

for some ξ in the interval. For linear interpolation with spacing h this gives at most h28max⁡|f′′|.

Runge's phenomenon and Chebyshev nodes

With equally spaced points the product ∏(x−xi) is enormous near the ends, and for functions like 11+25x2 the error grows without bound as n increases. The Chebyshev nodes

xi=cos⁡(2i+1)π2(n+1),i=0,…,n

make max⁡|∏(x−xi)| as small as possible on [−1, 1], namely 2−n, and the interpolant converges for every smooth function. For another interval, scale them linearly.

Worked example

A thermistor table gives 10.00 kΩ at 25 °C and 8.06 kΩ at 30 °C. Estimate R at 27 °C by linear interpolation.

Show the solution
  1. Interpolate. R=10.00+27−2530−25×(8.06−10.00)=10.00−0.776=9.224kΩ
  2. Compare with the curve. The true curve is convex (it's roughly exponential), so the line overestimates slightly: the exponential through both points gives 9.166 kΩ.
  3. How good that is. A thermistor table every 5 °C with linear interpolation is good to within about 1%.

Answer linear interpolation gives 9.224 kΩ, slightly high; the exponential through both points gives 9.166 kΩ.

Worked example

Find the quadratic through (0, 1), (1, 3), (3, 2) in Newton form.

Show the solution
  1. First divided differences. f[x0,x1]=3−11−0=2f[x1,x2]=2−33−1=−0.5
  2. Second divided difference. f[x0,x1,x2]=−0.5−23−0=−0.8333
  3. The Newton form. p(x)=1+2x−0.8333x(x−1)
  4. Evaluate at 2. p(2)=1+4−1.667=3.333

Answer p(x)=1+2x−0.8333x(x−1), with p(2)=3.333.

Worked example

Interpolate f(x)=11+25x2 on [−1, 1] with a degree-10 polynomial, once through equally spaced nodes and once through Chebyshev nodes. How large are the errors?

Show the solution
  1. Equally spaced nodes. With 11 equally spaced nodes the interpolant swings wildly near the ends: the largest error is 1.92, larger than the function itself.
  2. Chebyshev nodes. With the 11 Chebyshev nodes cos⁡(2i+1)π22 the largest error is 0.109.
  3. More equally spaced nodes. Adding them makes it worse, which is Runge's phenomenon.
  4. Why Chebyshev nodes work. They cluster near the ends, where the node polynomial ∏(x−xi) would otherwise be largest, and their error keeps shrinking as nodes are added.

Answer the largest error is 1.92 with equally spaced nodes and 0.109 with Chebyshev nodes.

Check

A table gives 12.49 kΩ at 20 °C, and the value changes by −1.8 kΩ over the next 10 °C. By linear interpolation, what's the resistance a fraction 0.7 of the way across that step?

Write units the way you normally would: 1.5 kΩ, 1500 Ω and 0.0015 MΩ are the same answer.

Check

The quadratic through (0, 1), (1, 3), (2, 4): what's its value at x = 0.5?

Check

For the points (0, 1), (1, 3), (3, 9), what's the divided difference f[x0,x1,x2]?

Check

What's Chebyshev node x0 for n = 8 (n + 1 nodes on [−1, 1])?

Check

A sine table has 256 entries per cycle, read with linear interpolation. What's the worst-case error, for amplitude 1?

Check

Why do Chebyshev nodes cluster near the ends of the interval?

Check

The quadratic through nodes 0, 1, 2 uses the Lagrange basis polynomials.

(a)

What is L0(x) at x = 1.5?

(b)

And L1(x)?

Check

Data f(0)=a, f(1)=b, f(2)=c.

Step 1

What is the divided difference f[x0,x1]?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

Why can adding more equally spaced points make a polynomial interpolant worse?

Practice

Keep practicing

9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.