Following a rate of change
A differential equation states how fast a quantity changes: dtdy=f(t,y). Money growing at a continuous rate r obeys dtdy=ry, with solution y0ert. A short rate pulled back to a long-run level θ obeys dtdr=κ(θ−r). Few equations have a formula for the solution, so we step through time numerically.
yn+1=yn+hf(tn,yn)(1) Euler's method follows the tangent for one short step h: new value = old value + step × slope. It is simple but only first-order accurate: halving h halves the error. Runge–Kutta of order 4 (RK4) samples the slope four times per step and blends them, yn+1=yn+6h(k1+2k2+2k3+k4), and its error shrinks like h4: halving h divides it by 16.
Growth at rate 1, two waysSolve
y′=y,
y(0)=1 up to
t=1 with
h=0.5. Euler:
y1=1+0.5⋅1=1.5,
y2=1.5+0.5⋅1.5=2.25, against
e=2.7183, an error of 0.4683. RK4 for one step to
t=0.5:
k1=1,
k2=1.25,
k3=1.3125,
k4=1.65625, so
y=1+60.5(1+2.5+2.625+1.65625)=1.6484, against the true
e0.5=1.6487.
- Euler: yn+1=yn+hf(tn,yn), 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.
A smaller step is not freeHalving 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
- 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