Maths & numbers

Differential equation solver (Euler, Heun, RK4, adaptive RK45)

Solve y′ = f(x, y) or a system of up to three first-order equations numerically, with step table, error against an exact solution and a plot.

Differential equation solver (Euler, Heun, RK4, adaptive RK45)
Esc to restore

Your inputs

Write y' = f(x, y), or for a system y1' = ..., y2' = ..., y3' = ... using x (or t), y1, y2, y3. The same expression syntax as the derivative calculator.

One number per equation, separated by commas, such as 1, 0 for y1(x₀) = 1 and y2(x₀) = 0.

An expression in x (or t), such as exp(-x^2). Leave empty when you do not know it.

Results update as you type. Larger files run when you press Update result.

Your result

Your result will appear here.

More actions

Your inputs stay in this browser. Nothing is uploaded or saved.

A clear answer. Here’s how.

One-step explicit Runge–Kutta methods for the initial value problem y′ = f(x, y), y(x₀) = y₀, where y may be a vector of up to three components. Euler: yₙ₊₁ = yₙ + h·f(xₙ, yₙ). Midpoint and Heun are the two classic second-order methods, and RK4 is the classic fourth-order method with weights 1/6, 1/3, 1/3, 1/6. For y′ = y one step multiplies y by 1 + h (Euler), 1 + h + h²/2 (Heun) or 1 + h + h²/2 + h³/6 + h⁴/24 (RK4). Fixed steps are equal: a step size that does not divide the interval is rounded to the nearest equal division, as stated in the note. The adaptive method is the Dormand–Prince RK5(4) pair (the one behind MATLAB’s ode45): a step is accepted when the embedded error estimate is within tol·(1 + |y|) for each component, and the next step is scaled by 0.9·err^(−1/5) within [0.2, 5]. Up to 2,000 rows are tabulated; with an exact solution the table adds the global error at every step. Guards: at most 100,000 fixed steps or 50,000 adaptive attempts, steps below 10⁻¹² and values beyond 10¹⁰⁰ stop the run with a message. These are explicit methods, so stiff problems are refused rather than solved with an implicit method; boundary value problems, delays and higher-order equations (rewrite them as a system) are not covered.

How this is checked

5 reference checks passed These 5 cases were run when this page was built, on 20 October 2026, and all reproduce within the stated tolerance. The same cases are part of the automated tests that run on every change to Toolmoz. Engine version 1.

See the checks and where each expected answer comes from
  1. Case 1

    Inputs
    Equation(s), one per line y' = yMethod eulerStep size h (first step for RK45) 0.1Exact solution for comparison (optional, one per equation) exp(x)
    Expected, and what Toolmoz gave
    Final y expected 2.5937424601, Toolmoz 2.5937424601Steps expected 10, Toolmoz 10
    Where the expected answer comes from
    Euler on y′ = y multiplies by 1 + h each step: 1.1¹⁰ = 2.5937424601 exactly (Python fractions)
    Allowed difference
    ±1e-12 relative
  2. Case 2

    Inputs
    Equation(s), one per line y' = yMethod rk4Step size h (first step for RK45) 0.1Exact solution for comparison (optional, one per equation) exp(x)
    Expected, and what Toolmoz gave
    Final y expected 2.718279744135166, Toolmoz 2.718279744135166Error at the end in y expected -0.0000020843238795813043, Toolmoz -0.0000020843238792700447
    Where the expected answer comes from
    RK4 on y′ = y multiplies by 1 + h + h²/2 + h³/6 + h⁴/24 = 265241/240000 each step; (265241/240000)¹⁰ = 2.718279744135166, which is e − 2.0843e-6 (Python fractions and decimal)
    Allowed difference
    ±1e-9 relative
  3. Case 3

    Inputs
    Equation(s), one per line y' = -2*x*yMethod rk4Step size h (first step for RK45) 0.1Exact solution for comparison (optional, one per equation) exp(-x^2)
    Expected, and what Toolmoz gave
    Final y expected 0.3678810664257649, Toolmoz 0.36788106642576485Exact final y expected 0.36787944117144233, Toolmoz 0.36787944117144233
    Where the expected answer comes from
    RK4 with h = 1/10 on y′ = −2xy, y(0) = 1, done in exact fractions in a separate Python script; the exact solution is exp(−x²), exp(−1) = 0.36787944117144233
    Allowed difference
    ±1e-12 relative
  4. Case 4

    Inputs
    The tool’s default inputs
    Expected, and what Toolmoz gave
    Final y expected 3.436559488270331, Toolmoz 3.4365594882703316Maximum absolute error expected 0.000004168647759162609, Toolmoz 0.000004168647758540089
    Where the expected answer comes from
    RK4 with h = 1/10 on y′ = x + y, y(0) = 1 in exact fractions (Python); against the exact solution 2eˣ − x − 1 the largest error over the ten steps is 4.1686e-6 at x = 1 (Python decimal)
    Allowed difference
    ±1e-9 relative
  5. Case 5

    Inputs
    Equation(s), one per line y1' = y2 y2' = -y1End x₁ 6.283185307179586Initial value(s) y(x₀) 1, 0Method rk45RK45 tolerance 1e-10Exact solution for comparison (optional, one per equation) cos(x) -sin(x)
    Expected, and what Toolmoz gave
    Final y1 expected 1, Toolmoz 0.9999999997986454Final y2 expected 0, Toolmoz -1.4278736179540452e-11
    Where the expected answer comes from
    Harmonic oscillator y″ = −y with y(0) = 1, y′(0) = 0 has the solution cos x, −sin x, which returns to (1, 0) after one period 2π; with tolerance 1e-10 the global error stays far below the 1e-6 allowed here
    Allowed difference
    ±0.000001 absolute

What this shows: the engine reproduces independently worked values for these cases. It does not prove every possible input is right. To test an answer you were given, see how to check a number; to see what is and is not checked across Toolmoz, see the accuracy ledger.

See a worked example

Worked example

A fixed demonstration, separate from the values you enter above.

Equation(s), one per line
y' = x + y
Start x₀
0
End x₁
1
Initial value(s) y(x₀)
1
Method
Classic Runge–Kutta RK4 (order 4)
Choose the steps by
Step size h
Step size h (first step for RK45)
0.1
Exact solution for comparison (optional, one per equation)
2*exp(x) - x - 1
Plot
Solution against x

Example result

First 5 rows of the example result
xyExact yError in y
0110
0.11.110341666671.11034183615-0.000000169484628554
0.21.24280514171.24280551632-0.000000374618950527
0.31.399716994131.39971761515-0.000000621026930991
0.41.583648480161.58364939528-0.000000915121169287

Classic Runge–Kutta (RK4) with 10 equal steps. The largest error against your exact solution is 0.00000416865 at x = 1. These are explicit methods: a stiff problem needs tiny steps and is refused after 100,000 fixed or 50,000 adaptive steps, and values beyond 10^100 stop the run.