WhatsApp us
University Maths25 Nov 2026

Runge-Kutta Method (4th Order): Formula, Worked Examples and Euler vs RK4

The fourth-order Runge-Kutta formula explained with full k₁ to k₄ working, an Euler vs RK4 error table against the exact solution, a nonlinear example, a second-order ODE as a system, and practice with checked answers.

Runge-Kutta Method (4th Order): Formula, Worked Examples and Euler vs RK4

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

MethodUpdate ruleSlope evaluations per stepLocal errorGlobal error
Euleryₙ + h f(xₙ, yₙ)1O(h²)O(h)
Modified Euler (Heun, RK2)average of start slope and predicted end slope2O(h³)O(h²)
RK4(k₁ + 2k₂ + 2k₃ + k₄)/64O(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).

xEulerRK4ExactEuler errorRK4 error
0.11.1000001.1048291.1048294.8 × 10⁻³1.2 × 10⁻⁷
0.21.2090001.2185971.2185979.6 × 10⁻³2.5 × 10⁻⁷
0.31.3259001.3401411.3401411.4 × 10⁻²3.8 × 10⁻⁷
0.41.4494901.4681751.4681751.9 × 10⁻²5.2 × 10⁻⁷
0.51.5784391.6012781.6012792.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.

StagePoint used (x, y, v)k (for y) = h vl (for v) = h(x + y)
1(0, 1, 0)00.1
2(0.05, 1, 0.05)0.0050.105
3(0.05, 1.0025, 0.0525)0.005250.10525
4(0.1, 1.00525, 0.10525)0.0105250.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

  1. The question names the method: use it, and state the formula before substituting.
  2. "Taylor series method" or "Picard's method": these are different methods; do not substitute RK4.
  3. "Modified Euler" or "Euler's predictor-corrector": a two-slope method; iterate the corrector if the question asks for it.
  4. Second-order equation: convert to a system first, then apply the named method to both equations.
  5. "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

  1. Use RK4 with h = 0.1 to find y(0.1) for dy/dx = 2x + y, y(0) = 1.
  2. Use Euler's method with h = 0.1 for the same equation to find y(0.2).
  3. RK4 with h = 0.2 gives an error of about 3.2 × 10⁻⁶ at some point. Estimate the error with h = 0.1.
  4. 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.
  5. 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.
Runge-Kutta methodRK4numerical methodsEuler methodB.Tech maths

Related guides

Keep exploring this maths topic

University Maths25 Nov 2026

Simpson's Rule and the Trapezoidal Rule: Formulas, Error Bounds and Worked Examples

Simpson's 1/3 rule, Simpson's 3/8 rule and the trapezoidal rule worked on the same integrals, with the error formulas, how to choose the number of intervals, a data-table question and practice with checked answers.

Simpson's ruletrapezoidal rulenumerical integrationnumerical methods

By Maths Bodhi Team

Read guide

University Maths18 Nov 2026

Newton-Raphson Method and Bisection Method: Formula, Iteration Tables and Examples

The Newton-Raphson formula and the bisection method worked step by step, with full iteration tables, how many iterations you need, when Newton fails, and practice questions with checked answers.

Newton-Raphson methodbisection methodnumerical methodsroot finding

By Maths Bodhi Team

Read guide

University Maths2 Nov 2026

How to Clear an Engineering Maths Back Paper (M1, M2 or M3)

A realistic plan for B.Tech students re-taking Engineering Mathematics M1, M2 or M3: confirm your scheme, map past papers, revise unit by unit, and master the high-yield question types through seven worked examples and a practice set with answers.

engineering maths back paperM1 back paperM2 back paperM3 back paper

By Maths Bodhi Team

Read guide

University Maths18 Nov 2026

Fourier Series in Engineering Maths: Coefficients, Square Wave and Half-Range Series

How to find Fourier series coefficients step by step, with five original worked examples (square wave, general period, half-range, harmonic analysis from a table) and the slips that cost marks in B.Tech exams.

Fourier seriesengineering mathematicshalf-range seriesharmonic analysis

By Maths Bodhi Team

Read guide

University Maths25 Nov 2026

Beta and Gamma Functions in Engineering Maths: Formulas and Worked Examples

Beta and gamma functions for B.Tech engineering maths: the definitions, the key properties and the beta-gamma relation, with six original worked integrals, the trigonometric form, and the slips that cost marks.

beta functiongamma functionengineering mathematicsimproper integrals

By Maths Bodhi Team

Read guide

University Maths25 Nov 2026

Cauchy Residue Theorem: Formula and Worked Examples for Engineering Maths

The Cauchy residue theorem explained through six original worked examples: simple and higher-order poles, a Laurent series residue, rational and trigonometric real integrals, and a Jordan's lemma integral, plus the slips that cost marks.

Cauchy residue theoremcomplex analysiscontour integrationengineering mathematics

By Maths Bodhi Team

Read guide