Following a rate of change
A differential equation states how fast a quantity changes: . Money growing at a continuous rate obeys , with solution . A short rate pulled back to a long-run level obeys . Few equations have a formula for the solution, so we step through time numerically.
Euler's method follows the tangent for one short step : new value = old value + step × slope. It is simple but only first-order accurate: halving halves the error. Runge–Kutta of order 4 (RK4) samples the slope four times per step and blends them, , and its error shrinks like : halving divides it by 16.
- Euler: , first-order accurate.
- RK4: four slopes per step blended with weights 1, 2, 2, 1; fourth-order accurate.
- Truncation error: what is lost by stepping instead of solving exactly.
Halving the step doubles the number of steps. Past a point, rounding error grows while truncation error no longer matters, and some stiff equations blow up unless the step is small enough. Compare two step sizes to estimate the error before you trust a result.
Lab · what's graded
7 tasks · 100 pts- Two Euler steps15 pts
- The Euler error15 pts
- One RK4 step20 pts
- Orders of accuracy10 pts
- Halving the step15 pts
- The Euler loop10 pts
- Why RK4 beats Euler15 pts