ODEs
Runge-Kutta (RK4)
The classical fourth-order Runge-Kutta method evaluates four slopes per step and takes a weighted average. Example: y'=x+y, y(0)=1, h=1/2; one step gives y(1/2)≈115/64≈1.797 versus true 2√e−3/2≈1.797.
Global error O(h⁴); highly accurate for smooth ODEs.
runge-kutta-rk4
RK4 computes four slope estimates k1..k4 then advances: k1 = h·f(x_n, y_n) k2 = h·f(x_n+h/2, y_n+k1/2) k3 = h·f(x_n+h/2, y_n+k2/2) k4 = h·f(x_n+h, y_n+k3) y_{n+1} = y_n + (1/6)(k1+2k2+2k3+k4)