5.1 Differentiation algorithms
Source: Ideas from Computational Physics (Landau, Páez, Bordeianu), Ch. 5 intro–§5.1.2. Rewritten in original wording. Continues 4.3b RNG test labs. Labs: 5.1b Differentiation labs.
This chapter opens with numerical differentiation — short but foundational — then spends most of its length on integration algorithms, ending with Monte Carlo integration (a different species). Here we only take the differentiation half through central differences.
5.1 The problem
Figure 5.1 is the spirit of the task: a projectile path with air resistance, measured only at discrete times. You need as a function of , and there is no closed formula to differentiate by hand.
The calculus limit is hostile on a machine. As shrinks, rides the edge of machine epsilon (subtractive cancellation), while dividing by a vanishing invites overflow. You need stable finite- formulas and an eye for the truncation / round-off tradeoff from Chapter 3.
Forward and central differences
Taylor-expand one step ahead, rearrange into a finite- slope, then compare the forward chord with the central chord . Walk the definition → rearrange → fd → cd — pick the matching equation at each step (lookalikes included).
Geometrically, forward difference is the slope of the chord from to (Figure 5.1 left); truncation is typically . Central difference cancels even powers of , leaving leading error when is smooth.
Parabola check. For , the exact derivative is , while forward difference returns (good only when ). Central difference returns the exact for every (higher derivatives vanish).
Finite differences
1 / 4Why is the literal limit definition dangerous on a computer?
Pick an answer to see if you are right.
Next: 5.1b Differentiation labs — implement forward and central differences and compare errors. Then 5.2 Extrapolated difference.