Euler and Runge–Kutta Calculator
Solve dy/dx = f(x, y) with y(x₀) = y₀ numerically by Euler's method, modified Euler, Heun's method or Runge–Kutta (2nd and 4th order), with the step-by-step table and the error against an accurate solution.
About the Euler and Runge–Kutta Calculator
Euler's method follows the tangent: yₙ₊₁ = yₙ + h f(xₙ, yₙ). It is simple but its error grows in proportion to h. Modified Euler (a predictor–corrector method) first predicts with an Euler step, then corrects with the average of the slopes at both ends; Heun's method corrects once, and the textbook modified Euler repeats the corrector until two rounds agree.
The fourth-order Runge–Kutta method averages four slopes, 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₃), giving yₙ₊₁ = yₙ + (k₁ + 2k₂ + 2k₃ + k₄)/6: its error shrinks like h⁴. Each answer is compared with RK4 at a much smaller step.
The formula
RK4: yₙ₊₁ = yₙ + (k₁ + 2k₂ + 2k₃ + k₄)/6
Worked example
dy/dx = x + y, y(0) = 1, h = 0.1
- k₁ = 0.1, k₂ = 0.11, k₃ = 0.1105, k₄ = 0.12105
- y(0.1) = 1 + (0.1 + 0.22 + 0.221 + 0.12105)/6 = 1.110342
- Exact: 2e^0.1 − 1.1 = 1.1103418…
Questions people ask
Modified Euler or Heun?
Books use the names differently. Heun's method applies the corrector once. Many Indian textbooks call the method "modified Euler" and repeat the corrector until two successive values agree; both are offered.
How do I choose h?
It must divide x − x₀ into whole steps. Halving h cuts Euler's error about in half and RK4's error about sixteen-fold.