Learn
Lesson · Differential Equations and Euler's Method · Stepping

Runge–Kutta: Four Slopes per Step

The classical Runge–Kutta method reads four slopes in each step, one at the start, two at the middle and one at the end, and combines them with weights 1, 2, 2, 1 over 6. When the right side depends on t alone, this is Simpson's rule, exact on cubics. The error is fourth order: halving h divides it by sixteen.

k₁ = f(tₙ, yₙ) k₂ = f(tₙ + h/2, yₙ + h·k₁/2) k₃ = f(tₙ + h/2, yₙ + h·k₂/2) k₄ = f(tₙ + h, yₙ + h·k₃) yₙ₊₁ = yₙ + h·(k₁ + 2k₂ + 2k₃ + k₄)/6 y′ = t⁴: halve h, error ÷ 16 exactly
Four slopes, weights 1, 2, 2, 1

Core ideas

What this lesson establishes

Three ideas: the four slopes, why the weights are 1, 2, 2, 1, and what fourth order buys.

1

Four slopes are read, one at the start, two at the middle, one at the end

The first is Euler's slope. The second is read at the middle of the step, using a half step along the first. The third is read at the middle again, using a half step along the second. The fourth is read at the end, using a whole step along the third. Each later slope corrects the point at which the previous one was taken.

2

The weights 1, 2, 2, 1 favour the middle

The step uses (k₁ + 2k₂ + 2k₃ + k₄)/6. The middle gets two readings and so double weight, and the weights add to 6. When f depends on t alone, k₂ = k₃, and the average is (f(start) + 4·f(middle) + f(end))/6: Simpson's rule on one piece, which integrates every cubic exactly.

3

Fourth order: halving the step divides the error by sixteen

The error at a fixed T is about C·h⁴, and the ratio of successive errors is near 16. Four slopes per step cost four times what Euler's method costs, and the error falls as the fourth power of the step, which an Euler refinement at the same cost does not reach on the equations here.

The material

Four slopes, one weighted average

The method, one step worked in full, the equation it solves exactly, the equation where the ratio is exactly 16, and why four slopes are not four Euler steps.

Definition · The classical Runge–Kutta method (RK4)

From (tₙ, yₙ) with step h: k₁ = f(tₙ, yₙ); k₂ = f(tₙ + h/2, yₙ + h·k₁/2); k₃ = f(tₙ + h/2, yₙ + h·k₂/2); k₄ = f(tₙ + h, yₙ + h·k₃); then yₙ₊₁ = yₙ + h·(k₁ + 2k₂ + 2k₃ + k₄)/6.

Four slopes are read per step. The lab runs it in exact fractions, up to 32 steps.

“Euler's Error and the Step Size” measured Euler's method at order 1, and “The Improved Euler Method” measured the improved method at order 2. This is the next rung. Take the simplest equation for seeing the weights: y′ = t⁴ from y(0) = 0, with one step of size h = 1. Because f has no y, the trial values play no part.

y′ = t⁴, y(0) = 0, one step, h = 1 slope read at value k₁ t = 0 0 k₂ t = 1/2 1/16 k₃ t = 1/2 1/16 k₄ t = 1 1 y₁ = (0 + 2/16 + 2/16 + 1)/6 = (5/4)/6 = 5/24

The true value is y(1) = 1/5, and 5/24 − 1/5 = 1/120. That is hand arithmetic, and it is the whole error of the step: h⁵/120 for a step of size h from t = 0. For t⁴ the fourth derivative is constant, so every step of size h misses by the same h⁵/120, and 1/h steps give h⁴/120 from t = 0 to t = 1.

Exact on a cubic

On y′ = t³ with exact solution t⁴/4, the lab prints 0 for the error at every one of the three step sizes, the ratio tile reads — because there is nothing to divide, and the order tile reads exact (error 0). The step is Simpson's rule, and Simpson's rule integrates a cubic without error, so RK4 has nothing to get wrong here.

Exactly 16 on a quartic

On y′ = t⁴ with exact solution t⁵/5, the errors at h = 1/4, 1/8 and 1/16 are 1/30720, 1/491520 and 1/7864320. Each is h⁴/120 exactly: (1/4)⁴/120 = 1/30720. The ratios are 16 and 16, and the order is 4.

Theorem · Runge–Kutta is fourth order

For a right-hand side with continuous fourth derivatives, the error of RK4 at a fixed T is approximately C·h⁴, so halving h divides it by about 16.

The lab shows the exact ratio on y′ = t⁴, and on y′ = y, where the errors are rounded, ratios of ≈ 14.4239 and ≈ 15.1898 that climb towards sixteen; it does not prove the order for every equation.

Example · Four slopes are not four Euler steps

Four Euler steps of size h/4 also read four slopes, and they advance by only h, each step starting from the previous step's inexact value. RK4's four slopes are combined into a single advance by h.

Count the work on y′ = t⁴ to T = 1. RK4 with h = 1/4 takes four steps, sixteen slope readings, and has error 1/30720. Euler with sixteen readings is sixteen steps of h = 1/16, with error 19627/655360 ≈ 0.0299484, rounded, which is about 920 times larger. Switch the Method menu to Euler and read the third error to see it.

The third preset runs the method on y′ = y. The true value e is irrational, so every error is rounded and the observed order, ≈ 3.92503, is near 4 and marked ≈.

Interactive

Order of a method

Errors at h, h/2 and h/4, and their ratios

The order of a methodhalve h and watch the error
log₂ error against log₂ h

Method

One Runge–Kutta step by hand

Four readings and a weighted average, in this order.

1

Read the slope at the start

k₁ = f(tₙ, yₙ).

2

Read the slope at the middle, along k₁

k₂ = f(tₙ + h/2, yₙ + h·k₁/2): go half a step along k₁ and read there.

3

Read the slope at the middle again, along k₂

k₃ = f(tₙ + h/2, yₙ + h·k₂/2): same time, a better value.

4

Read the slope at the end, along k₃

k₄ = f(tₙ + h, yₙ + h·k₃): a whole step along k₃.

5

Combine with weights 1, 2, 2, 1 over 6

yₙ₊₁ = yₙ + h·(k₁ + 2k₂ + 2k₃ + k₄)/6. The weights add to 6; do not divide by 4.

Weights, exactness and sixteen

Score 0 / 0

One step of size 1 on y′ = t⁴

Take the single step from y(0) = 0 to t = 1, compare with the true value, and state the error as a power of h.

f = t⁴, no y; y₀ = 0; h = 1 k₁ = f(0) = 0 k₂ = f(1/2) = 1/16 k₃ = f(1/2) = 1/16 k₄ = f(1) = 1 y₁ = 1·(0 + 2·(1/16) + 2·(1/16) + 1)/6 = (5/4)/6 = 5/24 true y(1) = 1/5; error = 5/24 − 1/5 = 1/120 from t = 0 to 1 with h = 1/4: (1/4)⁴/120 = 1/30720

The one-step error is 1/120, which is h⁵/120 at h = 1. From t = 0 to t = 1 with step h, there are 1/h steps, each missing by h⁵/120, and the total is h⁴/120: 1/30720 at h = 1/4, as the lab prints. Halving h divides h⁴ by exactly sixteen.

For a rehearsal, take the single step on y′ = t³ with h = 1. The readings are 0, 1/8, 1/8, 1, so y₁ = (0 + 2/8 + 2/8 + 1)/6 = (3/2)/6 = 1/4, which is the true value, with error zero.

Common mistakes

1
Thinking Runge–Kutta is four Euler steps, so it costs the same as Euler with h/4 and does no betterThe cost is the same, four slope readings, and the error is not. On y′ = t⁴ with sixteen readings, RK4 at h = 1/4 has error 1/30720 and Euler at h = 1/16 has 19627/655360, about 920 times more. The four slopes are combined into one step, and the combination is what raises the order.
2
Averaging the four slopes equallyThe middle slope is read twice and the weights are 1, 2, 2, 1 over 6. On the worked example the equal average gives (0 + 1/16 + 1/16 + 1)/4 = 9/32, against 5/24 with the right weights and 1/5 for the truth: a much larger error.
3
Taking fourth order to mean exactThe lab prints 0 on y′ = t³ and not on y′ = t⁴, where the error is h⁴/120. Fourth order says how fast the error falls; exactness is a property of the equation, and here it comes from the right side being a polynomial in t of degree three or less, which Simpson's rule integrates without error. On y′ = y, whose solution is no polynomial at all, the error is never zero.

Check your understanding

✓
Finish when you can write the four slopes and weights of RK4 and show its error ratio is 16.

You should be able to compute k₁ to k₄ and the step for a given equation, state that the weights are 1, 2, 2, 1 over 6, explain why the method is exact on y′ = t³, and read the ratio 16 and the order 4 from the lab at three step sizes on y′ = t⁴.

Note: Three methods, three orders, and all of them assume the solution is there to be approached. “Blow-Up and the Interval of Existence” shows an equation where it is not.

Kept in this browser only, for you. Nothing is sent anywhere and nothing checks it. Carry it to another device.

Feedback and recommendations

Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.

No recommendations yet for this lesson.