How to use the Runge-Kutta RK4 Calculator
- 1. Type dy/dxEnter f(x, y), for example x + y or x^2 + y^2.
- 2. Set x₀, y₀, h and xGive the initial condition, the step size and where you want y.
- 3. Read the tableEach row shows k₁, k₂, k₃, k₄ and the next y.
The RK4 formulas
For dy/dx = f(x, y) with y(x₀) = y₀ and step 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
The four slopes are averaged with weights 1, 2, 2, 1. The error per step is of order h⁵, which makes RK4 the standard choice in exams and in real code.
Worked example
Solve dy/dx = x + y, y(0) = 1, and find y(0.2) with h = 0.1.
Step 1: k₁ = 0.1(0 + 1) = 0.1; k₂ = 0.1(0.05 + 1.05) = 0.11; k₃ = 0.1(0.05 + 1.055) = 0.1105; k₄ = 0.1(0.1 + 1.1105) = 0.12105. So y(0.1) = 1 + (0.1 + 0.22 + 0.221 + 0.12105)/6 = 1.110342.
Step 2 from (0.1, 1.110342) gives k₁ = 0.121034, k₂ = 0.132086, k₃ = 0.132638, k₄ = 0.144298 and y(0.2) = 1.242805. The exact solution 2eˣ − x − 1 gives 1.242806.
Choosing the step size
The target x must be a whole number of steps from x₀. Halving h makes RK4 about 16 times more accurate, so if two runs with h and h/2 agree to your decimals, the answer is reliable. Very steep or stiff equations may need a much smaller h. For first-order problems in other forms, the Newton-Raphson calculator handles algebraic equations, while this tool handles differential ones.
Frequently asked questions
Is RK4 the same as the fourth-order Runge-Kutta method?
Yes. RK4 is short for the classical fourth-order Runge-Kutta method.
Can it solve second-order equations?
Not directly. A second-order equation must be split into two first-order equations, which this single-equation tool does not do.
Why must (x − x₀)/h be a whole number?
RK4 moves in equal steps of h, so the target must land exactly on a step.
Is this calculator free?
Yes. You enter your name and WhatsApp number once when you see your result, and other Uncodemy tools then open without the form.