Truncation Error vs. Roundoff Error in Finite Differences

Summary

When approximating derivatives with finite differences, truncation error shrinks as the step size hh decreases — but roundoff error grows. Below a certain hh, floating-point noise wins. Central differences reach O(h2)O(h^2) truncation error and are usually preferable to forward differences.


Forward difference

A first-order forward approximation:

f(x)f(x+h)f(x)hf'(x) \approx \frac{f(x+h) - f(x)}{h}

From Taylor expansion about xx:

f(x+h)=f(x)+hf(x)+h22f(x)+O(h3)f(x+h) = f(x) + h f'(x) + \frac{h^2}{2} f''(x) + O(h^3)

Rearranging:

f(x)=f(x+h)f(x)hh2f(x)+O(h2)f'(x) = \frac{f(x+h) - f(x)}{h} - \frac{h}{2} f''(x) + O(h^2)

So the truncation error of the forward-difference formula is O(h)O(h) — halving hh roughly halves the discretization error.


Roundoff error and catastrophic cancellation

In floating-point arithmetic, subtracting two nearly equal numbers loses significant digits. Example:

Quantity Value
f(x+h)f(x+h) 1.0000000000011.000000000001
f(x)f(x) 1.0000000000001.000000000000
f(x+h)f(x)f(x+h) - f(x) 0.0000000000010.000000000001

The true difference is dominated by floating-point noise rather than the mathematical signal. This is catastrophic cancellation.

Trade-off:

  • Smaller hh → smaller truncation error
  • Too small hh → larger relative roundoff error

There is an optimal step size that balances both effects.


Central difference — why it is better

Expand both directions:

f(x+h)=f(x)+hf(x)+h22f(x)+h36f(x)+O(h4)f(x+h) = f(x) + h f'(x) + \frac{h^2}{2} f''(x) + \frac{h^3}{6} f'''(x) + O(h^4)

f(xh)=f(x)hf(x)+h22f(x)h36f(x)+O(h4)f(x-h) = f(x) - h f'(x) + \frac{h^2}{2} f''(x) - \frac{h^3}{6} f'''(x) + O(h^4)

Subtracting:

f(x+h)f(xh)=2hf(x)+h33f(x)+O(h5)f(x+h) - f(x-h) = 2h f'(x) + \frac{h^3}{3} f'''(x) + O(h^5)

Solve for f(x)f'(x):

f(x)=f(x+h)f(xh)2hh26f(x)+O(h4)f'(x) = \frac{f(x+h) - f(x-h)}{2h} - \frac{h^2}{6} f'''(x) + O(h^4)

The central-difference formula has truncation error O(h2)O(h^2) — one order better than forward difference — while even-order terms cancel by symmetry.


Takeaways

  1. Truncation error comes from the Taylor-series approximation; it decreases as h0h \to 0.
  2. Roundoff error grows when hh is too small because of catastrophic cancellation.
  3. Central differences give O(h2)O(h^2) accuracy and are the standard choice when both f(x+h)f(x+h) and f(xh)f(x-h) are available.
  4. In practice, choose hh using a balance rule (often related to machine epsilon and the scale of ff).

References & code

Add notes, plots, or experiments here when ready.

Truncation Error vs. Roundoff Error in Finite Differences | Laramie Community Hub