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.
Example
Combine four weighted slopes for one fourth-order step.
highlighted = computed this step
Step 1 — Set up
Set up the Runge-Kutta method for one step.
y′=x+yy(0)=1h=21
Step 2 — Compute k1
Compute the next Runge-Kutta slope.
k1=21⋅(0+1)=21
Step 3 — Compute k2
Compute the next Runge-Kutta slope.
k2=21⋅(41+45)=43
Step 4 — Compute k3
Compute the next Runge-Kutta slope.
k3=21⋅(41+811)=1613
Step 5 — Compute k4
Compute the next Runge-Kutta slope.
k4=21⋅(21+1629)=3237
Step 6 — Weighted update
Combine k values with weights 1, 2, 2, 1 over 6.
y1=1+61(21+2⋅43+2⋅1613+3237)=64115
Step 7 — Result
State the Runge-Kutta approximation.
y(21)=64115
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)