+15 XP

Bonus: A Smarter Step (RK4)

Euler takes the slope at the start of a step and commits to it — a bit naive on a curve. The 4th-order Runge–Kutta (RK4) method is smarter: it samples the slope four times across the step and cleverly averages them.

Think of crossing a river: Euler picks a direction once and swims blindly. RK4 checks the current at the near bank, twice in the middle, and at the far bank, then blends those into a much better heading. Same step size, far less drift.

Compare them head-to-head. Both use the same Δt against the exact curve — watch how much closer RK4 (cyan) stays than Euler (red):

Δt — step sizeΔt = 1.00
12345time, t (years)population
exact
Euler
RK4
Euler error: 0.626RK4 error: 0.000

Same step size, two methods. RK4 peeks at the slope four times within each step and averages them, so it tracks the exact curve far better than plain Euler. Halve Δt and RK4's error drops ~16× (Δt⁴) versus Euler's ~2×.

RK4 is 4th order: halve Δt and its error drops by a factor of ~2⁴ = 16×, versus Euler's measly ~2×. That accuracy is why RK4 is a workhorse for serious simulations — at the cost of a bit more arithmetic per step.