Initial value problems
An initial value problem asks for the function y(t) that satisfies a first-order differential equation y′ = f(t, y) and a starting condition y(t₀) = y₀. Systems of equations, and higher-order equations rewritten as systems, take the same form, so stepping methods for this one problem cover most of applied dynamics.
The Euler method
Euler's method is the simplest stepper. From the current point it follows the tangent line for one step of length h:
yn+1 = yn + h · f(tn, yn)
The method is easy to understand and implement, but its error per step is only first order in h: halving the step roughly halves the error. Accurate answers can demand very small steps, and the method's simplicity is its main virtue.
Runge-Kutta methods
Runge-Kutta methods improve accuracy by sampling the slope at several places within each step and combining the samples. The classic fourth-order method (RK4) uses four evaluations per step:
k1 = h * f(t, y)
k2 = h * f(t+h/2, y + k1/2)
k3 = h * f(t+h/2, y + k2/2)
k4 = h * f(t+h, y + k3)
y = y + (k1 + 2*k2 + 2*k3 + k4) / 6.0
t = t + hIts error is fourth order in h: halving the step cuts the error by roughly a factor of sixteen, which is why RK4 has been a workhorse for decades. The same idea extends to higher orders and to embedded pairs that estimate their own error for automatic step-size control.
Practical considerations
- Choose h small enough for accuracy but not so small that rounding error and runtime dominate.
- For stiff equations — where some components change far faster than others — explicit methods need impractically small steps; implicit methods are the standard remedy.
- Verify a new integrator against a problem with a known solution before trusting it on the real one.