The fourth-order Runge-Kutta method (RK4) solves dy/dx = f(x, y), y(x₀) = y₀ step by step: from (xₙ, yₙ) it computes four slopes k₁, k₂, k₃, k₄ and moves to y₍ₙ₊₁₎ = yₙ + (k₁ + 2k₂ + 2k₃ + k₄)/6. Its global error is proportional to h⁴, so halving the step size cuts the error by about 16, compared with about 2 for Euler's method. In exams you are usually asked for one or two steps with every k shown, so neat layout matters as much as the formula.
This guide gives the formula, works three original examples in full, and puts Euler and RK4 side by side against an exact solution so you can see the difference in numbers, not just in words.
The RK4 formula
With step size h:
k₁ = h f(xₙ, yₙ)
k₂ = h f(xₙ + h/2, yₙ + k₁/2)
k₃ = h f(xₙ + h/2, yₙ + k₂/2)
k₄ = h f(xₙ + h, yₙ + k₃)
y₍ₙ₊₁₎ = yₙ + (k₁ + 2k₂ + 2k₃ + k₄)/6
Read it as a weighted average of four slope estimates: one at the start, two at the midpoint (the second using a better midpoint value), one at the end. The weights 1, 2, 2, 1 are those of Simpson's rule, which is why RK4 reduces to Simpson's rule when f depends on x only.
Some books define k₁ = f(xₙ, yₙ) without the h and put h in the last line: y₍ₙ₊₁₎ = yₙ + (h/6)(k₁ + 2k₂ + 2k₃ + k₄). Both versions are correct. Mixing them inside one answer is the slip to avoid.
If you want help with numerical methods alongside the rest of your engineering maths syllabus, our engineering mathematics tutoring page explains how online sessions with Ajay Vatsyayan are run.
Euler, Heun and RK4 compared
| Method | Update rule | Slope evaluations per step | Local error | Global error |
|---|---|---|---|---|
| Euler | yₙ + h f(xₙ, yₙ) | 1 | O(h²) | O(h) |
| Modified Euler (Heun, RK2) | average of start slope and predicted end slope | 2 | O(h³) | O(h²) |
| RK4 | (k₁ + 2k₂ + 2k₃ + k₄)/6 | 4 | O(h⁵) | O(h⁴) |
RK4 costs four evaluations per step instead of one, but the accuracy gain is so large that, for smooth problems, it is cheaper than Euler for any useful accuracy.
Example 1: one RK4 step in full
Solve dy/dx = y − x², y(0) = 1, and find y(0.1) with h = 0.1.
Here f(x, y) = y − x², x₀ = 0, y₀ = 1.
k₁ = 0.1 × f(0, 1) = 0.1 × (1 − 0) = 0.1
k₂ = 0.1 × f(0.05, 1 + 0.05) = 0.1 × (1.05 − 0.0025) = 0.10475
k₃ = 0.1 × f(0.05, 1 + 0.052375) = 0.1 × (1.052375 − 0.0025) = 0.1049875
k₄ = 0.1 × f(0.1, 1 + 0.1049875) = 0.1 × (1.1049875 − 0.01) = 0.10949875
Combine.
y₁ = 1 + (0.1 + 2(0.10475) + 2(0.1049875) + 0.10949875)/6
y₁ = 1 + 0.62897375/6 = 1.104829 (6 d.p.)
This equation is linear, so it has an exact solution: y = x² + 2x + 2 − eˣ. At x = 0.1 that gives 1.104829 as well. The RK4 error after one step is about 1.2 × 10⁻⁷.
Euler vs RK4 against the exact answer
Continue Example 1 to x = 0.5 with h = 0.1 using both methods (values to six decimal places).
| x | Euler | RK4 | Exact | Euler error | RK4 error |
|---|---|---|---|---|---|
| 0.1 | 1.100000 | 1.104829 | 1.104829 | 4.8 × 10⁻³ | 1.2 × 10⁻⁷ |
| 0.2 | 1.209000 | 1.218597 | 1.218597 | 9.6 × 10⁻³ | 2.5 × 10⁻⁷ |
| 0.3 | 1.325900 | 1.340141 | 1.340141 | 1.4 × 10⁻² | 3.8 × 10⁻⁷ |
| 0.4 | 1.449490 | 1.468175 | 1.468175 | 1.9 × 10⁻² | 5.2 × 10⁻⁷ |
| 0.5 | 1.578439 | 1.601278 | 1.601279 | 2.3 × 10⁻² | 6.5 × 10⁻⁷ |
Now halve the step to h = 0.05. At x = 0.5 the Euler error falls from 2.28 × 10⁻² to 1.16 × 10⁻² (a factor of about 2), while the RK4 error falls from 6.53 × 10⁻⁷ to 4.12 × 10⁻⁸ (a factor of about 16). That is O(h) against O(h⁴), measured rather than quoted. The same check is a useful way to estimate the error of your own answer when no exact solution exists: run with h and h/2 and compare.
Example 2: a nonlinear equation over two steps
Use RK4 with h = 0.2 to find y(0.4) for dy/dx = x + √y, y(0) = 1.
There is no simple exact solution, which is exactly when numerical methods earn their place.
Step 1: x₀ = 0, y₀ = 1.
Working to seven decimal places:
k₁ = 0.2(0 + √1) = 0.2
k₂ = 0.2(0.1 + √1.1) = 0.2(0.1 + 1.0488088) = 0.2297618
k₃ = 0.2(0.1 + √1.1148809) = 0.2(0.1 + 1.0558792) = 0.2311758
k₄ = 0.2(0.2 + √1.2311758) = 0.2(0.2 + 1.1095836) = 0.2619167
y₁ = 1 + (0.2 + 0.4595236 + 0.4623516 + 0.2619167)/6 = 1.2306320
Step 2: x₁ = 0.2, y₁ = 1.2306320.
k₁ = 0.2618677, k₂ = 0.2933723, k₃ = 0.2947184, k₄ = 0.3270102
y₂ = 1.2306320 + (0.2618677 + 0.5867446 + 0.5894368 + 0.3270102)/6 = 1.5248086
So y(0.4) ≈ 1.524809 (6 d.p.). A run with a much smaller step gives 1.524811, so two RK4 steps of size 0.2 are already correct to five decimal places.
Notice that k₂ and k₃ use y-values like 1 + k₁/2, not y₀ + h/2. Students sometimes add h/2 to y as well as to x.
Example 3: a second-order ODE as a system
RK4 handles y″ = F(x, y, y′) by writing it as two first-order equations. Let v = y′. Then
y′ = v, v′ = F(x, y, v)
and you run RK4 on both together, using the k's for y and the k's for v (call them l's) at the same time.
Take y″ = x + y, y(0) = 1, y′(0) = 0, and find y(0.1) and y′(0.1) with h = 0.1.
| Stage | Point used (x, y, v) | k (for y) = h v | l (for v) = h(x + y) |
|---|---|---|---|
| 1 | (0, 1, 0) | 0 | 0.1 |
| 2 | (0.05, 1, 0.05) | 0.005 | 0.105 |
| 3 | (0.05, 1.0025, 0.0525) | 0.00525 | 0.10525 |
| 4 | (0.1, 1.00525, 0.10525) | 0.010525 | 0.110525 |
y₁ = 1 + (0 + 0.01 + 0.0105 + 0.010525)/6 = 1.005171
v₁ = 0 + (0.1 + 0.21 + 0.2105 + 0.110525)/6 = 0.105171
The exact solution is y = eˣ − x, so y(0.1) = 1.005171 and y′(0.1) = 0.105171. Both agree to six decimal places.
The trap here is updating y with its k's and then using the new y inside the l's of the same step. Every stage must use the values from the row above, not values you have already updated.
Choosing a method in an exam
- The question names the method: use it, and state the formula before substituting.
- "Taylor series method" or "Picard's method": these are different methods; do not substitute RK4.
- "Modified Euler" or "Euler's predictor-corrector": a two-slope method; iterate the corrector if the question asks for it.
- Second-order equation: convert to a system first, then apply the named method to both equations.
- "Compare with the exact solution": solve analytically, then tabulate absolute errors as above.
Where students lose marks
- Calculator in degrees for f involving sin x or cos x. Set radians before k₁.
- Wrong midpoint. k₂ and k₃ use x + h/2, k₄ uses x + h. Write the point being substituted before evaluating.
- Forgetting the factor h (or applying it twice) when switching between the two notations.
- Rounding k values to two or three digits. Carry six or more and round only y₍ₙ₊₁₎.
- Weights 1, 2, 2, 1 divided by 4 instead of 6. The weights sum to 6.
- Not labelling steps. In a two-step question, write x₁, y₁ clearly before starting the second set of k's. Method marks depend on it.
Practice set
- Use RK4 with h = 0.1 to find y(0.1) for dy/dx = 2x + y, y(0) = 1.
- Use Euler's method with h = 0.1 for the same equation to find y(0.2).
- RK4 with h = 0.2 gives an error of about 3.2 × 10⁻⁶ at some point. Estimate the error with h = 0.1.
- Write y″ + 3y′ + 2y = 0, y(0) = 1, y′(0) = 0 as a first-order system and take one Euler step with h = 0.1.
- Use one RK4 step with h = 0.2 for dy/dx = −2xy, y(0) = 1, and compare with the exact value e^(−0.04).
Answers. (1) k₁ = 0.1, k₂ = 0.115, k₃ = 0.11575, k₄ = 0.131575, so y(0.1) ≈ 1.11551 (exact 3e^(0.1) − 2.2 ≈ 1.11551). (2) y(0.1) = 1.1, y(0.2) = 1.23. (3) About 3.2 × 10⁻⁶/16 = 2 × 10⁻⁷. (4) y′ = v, v′ = −3v − 2y; after one step y = 1, v = −0.2. (5) y(0.2) ≈ 0.960789, matching e^(−0.04) = 0.960789 to six decimal places.
Where RK4 leads next
RK4 is the workhorse behind most ODE solvers you will meet in later courses and software, and adaptive versions change h automatically using the h versus h/2 idea above. Before relying on it, make sure you can solve the equations exactly when possible: the guide to separable, linear and exact first-order equations and the second-order linear ODE examples give the exact solutions you compare against. If you met Euler's method at school, the IB AI HL differential equations guide is a short bridge. Root-finding sits in the same numerical methods unit; see our Newton-Raphson and bisection iteration tables.
How Maths Bodhi helps
We practise the k₁ to k₄ layout until it is quick and error-free, link numerical answers to exact methods, and review your own attempts. For the full ODE course, see our differential equations tutoring page.
Home tuition is available in Gurgaon (Gurugram). Students elsewhere in India and abroad learn with us online. You can book a free demo class.
Written and checked by the Maths Bodhi team (November 2026).
Frequently asked questions
- What is the Runge-Kutta 4th order formula?
- y₍ₙ₊₁₎ = yₙ + (k₁ + 2k₂ + 2k₃ + k₄)/6, with k₁ = hf(xₙ, yₙ), k₂ = hf(xₙ + h/2, yₙ + k₁/2), k₃ = hf(xₙ + h/2, yₙ + k₂/2), k₄ = hf(xₙ + h, yₙ + k₃).
- Why is RK4 more accurate than Euler's method?
- Euler uses one slope per step and has global error O(h); RK4 averages four slopes and has global error O(h⁴).
- What is the order of the Runge-Kutta 4th order method?
- Local error O(h⁵) per step and global error O(h⁴).
- How do you use Runge-Kutta for a second-order differential equation?
- Set v = y′ to get two first-order equations and apply RK4 to both at once, using the previous step's values in every stage.
- Is RK4 the same as Simpson's rule?
- When f depends only on x, the RK4 step reduces to Simpson's rule on [xₙ, xₙ + h].
- Should I use radians in Runge-Kutta problems?
- Yes; whenever f involves trigonometric functions, the calculator must be in radians.
