Often a function is known only at a set of points, as in a table. Interpolation estimates its value at a point between them.
Interpolation and Finite Differences
Given values y0, y1, …, yn of a function at points x0, x1, …, xn, interpolation finds the value of y at some x inside the range, and extrapolation finds it outside. When the points are equally spaced, with x(i) = x0 + ih and step h, we use finite differences. The forward difference is Δy(i) = y(i+1) − y(i). The second difference is Δ²y(i) = Δy(i+1) − Δy(i), and so on. The backward difference is ∇y(i) = y(i) − y(i−1). The differences are set out in a difference table. For a polynomial of degree n, the nth differences are constant.
Definition: Interpolation. The estimation of the value of a function at a point lying between known data points, using a polynomial that passes through those points.
Newton's Forward Formula
To interpolate near the beginning of the table, let p = (x − x0)/h. Then y(x) = y0 + pΔy0 + p(p − 1)/2! Δ²y0 + p(p − 1)(p − 2)/3! Δ³y0 + … The differences used are those along the top diagonal of the table.
Newton's Backward Formula
To interpolate near the end of the table, let p = (x − xn)/h, which is negative. Then y(x) = yn + p∇yn + p(p + 1)/2! ∇²yn + p(p + 1)(p + 2)/3! ∇³yn + … The differences used are those along the bottom diagonal. Both formulas give the same polynomial, but using the one nearer to x needs fewer terms for good accuracy.
Table 3.4: Forward and backward formulas
| Feature | Forward | Backward |
|---|---|---|
| Use near | Start of table | End of table |
| p | (x − x0)/h | (x − xn)/h |
| Differences | Δy0, Δ²y0, … | ∇yn, ∇²yn, … |
| Terms | p, p(p − 1), … | p, p(p + 1), … |
Example 3.4: Forward interpolation
Problem: Given x: 1, 2, 3, 4 and y: 1, 8, 27, 64 (y = x³), find y at x = 1.5 by Newton's forward formula.
Solution:
- Differences: Δy0 = 7, Δ²y0 = 12, Δ³y0 = 6. h = 1, p = (1.5 − 1)/1 = 0.5.
- y = 1 + 0.5 × 7 + (0.5)(−0.5)/2 × 12 + (0.5)(−0.5)(−1.5)/6 × 6.
- = 1 + 3.5 − 1.5 + 0.375 = 3.375.
Result: y(1.5) = 3.375, which equals 1.5³ exactly, since the data come from a cubic.
y = [1, 8, 27, 64]
d = [y]
while len(d[-1]) > 1:
r = d[-1]
d.append([r[i + 1] - r[i] for i in range(len(r) - 1)])
p, val, term = 0.5, 0, 1
for k in range(len(d)):
val += term * d[k][0]
term *= (p - k) / (k + 1)
print([row[0] for row in d], val)
Output
[1, 7, 12, 6] 3.375
Common mistakes
- Using Newton's formulas when the points are not equally spaced.
- Using the wrong sign in p for the backward formula. p is negative near the end.
- Taking the wrong diagonal of the difference table.
Key takeaways
- Finite differences are used for equally spaced data.
- Forward formula near the start, backward formula near the end.
- p = (x − x0)/h for forward and (x − xn)/h for backward.
- For a polynomial of degree n, the nth differences are constant.
Practice questions
- What is interpolation?
- When is Newton's backward formula used?
- Define the first forward difference.
Answers to the practice questions
- Estimating the value of a function between known data points.
- To interpolate near the end of a table of equally spaced values.
- Δy(i) = y(i+1) − y(i).
Sources
- Official BCA syllabus Mathematics Foundations to Computer Science II, course code 25BCA402DS01, Unit III
