Finite-Difference Derivatives get better as $h$ shrinks, so why not take $h = 10^{-15}$? Because $f(x + h)$ and $f(x)$ become nearly equal, and subtracting them is Round-Off and Cancellation. Each stored value of $f$ has a rounding error of size about $\varepsilon|f|$ (with $\varepsilon \approx 10^{-16}$), and dividing their difference by a tiny $h$ magnifies that error.
For the forward difference (with $|f| \approx 1$ and $|f''| \le M$) the two errors add up to about $$E(h) = \underbrace{\frac{M}{2}h}_{\text{truncation}} + \underbrace{\frac{2\varepsilon}{h}}_{\text{round-off}}.$$ The first term falls as $h$ shrinks; the second grows.
Key idea
Why it works
Worked example: The best h for a forward difference
- $h^{*} = 2\sqrt{10^{-16}/1} = 2 \times 10^{-8}$.
- $E(h^{*}) = 2\sqrt{1 \times 10^{-16}} = 2 \times 10^{-8}$.
- So about 8 correct digits at best, however much effort goes in.
Answer: $h^{*} = 2 \times 10^{-8}$, error about $2 \times 10^{-8}$
Worked example: Real numbers
- Forward: $h = 10^{-2}$: $4.2 \times 10^{-3}$; $10^{-4}$: $4.2 \times 10^{-5}$; $10^{-6}$: $4.2 \times 10^{-7}$; $10^{-8}$: $3 \times 10^{-9}$; $10^{-10}$: $6 \times 10^{-8}$; $10^{-12}$: $4 \times 10^{-5}$.
- Central: $h = 10^{-2}$: $9 \times 10^{-6}$; $10^{-4}$: $9 \times 10^{-10}$; $10^{-6}$: $3 \times 10^{-11}$; then it grows again.
- Down to $h = 10^{-6}$ the forward error falls by 100 per factor-of-100 step in $h$ (order 1). Below $10^{-8}$ it rises: at $h = 10^{-12}$ it is as bad as at $h = 10^{-4}$. The central difference bottoms out lower, near $h = 10^{-5}$ or $10^{-6}$.
Answer: a V shape, with its bottom near the predicted best h
Worked example: Round-off alone
- $\frac{2 \times 10^{-16}}{10^{-12}} = 2 \times 10^{-4}$.
- That matches the size of the observed error: at tiny $h$, almost everything you compute is round-off.
Answer: about $2 \times 10^{-4}$
Common mistake