Differential equation solver

Enter the right-hand side f(x, y), the starting point and the step size. The solver steps from x₀ to the end point with Euler's method, Heun's improved Euler method or the classical fourth-order Runge–Kutta method and shows y at each step and a graph.

Use x and y, for example x + y, -2*x*y or sin(x) - y. Write products with * or a space when two letters meet: x*y, not xy.
The initial condition is y(x₀) = y₀. The end x may be left of x₀ to solve backwards.
If h does not divide the interval evenly, it is reduced slightly so the last step lands exactly on the end x.
Value at the endy(1) ≈ 3.436559488
Step size used
0.1
Steps
10
x = 0
1
x = 0.1
1.110341667
x = 0.2
1.242805142
x = 0.3
1.399716994
x = 0.4
1.58364848
x = 0.5
1.797441277
x = 0.6
2.044235924
x = 0.7
2.327503253
x = 0.8
2.651079127
x = 0.9
3.019202828
x = 1
3.436559488

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Type f(x, y), the right-hand side of y’ = f(x, y).
  2. Enter the initial condition x₀, y₀, the end x and the step size h.
  3. Pick a method and read y at the end, the table and the graph.

How it works

The interval from x₀ to the end is split into n = ⌈|x_end − x₀| / h⌉ equal steps. At each step the chosen method estimates the slope from f and moves y forward:

  • Euler uses the slope at the start of the step.
  • Heun averages the slope at the start and at the end predicted by Euler.
  • RK4 combines four slopes: at the start, twice at the middle and at the end, weighted 1 : 2 : 2 : 1.

Worked example

y’ = x + y, y(0) = 1, h = 0.1, up to x = 1. The exact solution is y = 2eˣ − x − 1, so y(1) = 2e − 2 ≈ 3.436564. RK4 gives 3.436559 (error 5·10⁻⁶); Euler with the same step gives only 3.187485.

Tips

  • Stiff equations, such as y’ = −50(y − cos x), need a small step with these explicit methods or the values oscillate.
  • Write powers as x^2 and use exp(x) or e^x for the exponential.

Frequently asked questions

Which method should I choose?

Runge–Kutta 4 for accuracy: its error shrinks with h⁴, so halving the step cuts the error about sixteenfold. Euler's method is the simplest and the one taught first, but its error only shrinks in proportion to h. Heun's method sits in between, with error proportional to h².

How accurate is the result?

It is an approximation. For y' = y, y(0) = 1 and h = 0.1, the exact y(1) is e = 2.718281828; Euler gives 2.593742, Heun 2.714081 and RK4 2.718280. A good check is to halve h and see whether the answer changes.

What are the formulas?

Euler: yₙ₊₁ = yₙ + h·f(xₙ, yₙ). Heun: average the slope at the start and at the Euler-predicted end. RK4: yₙ₊₁ = yₙ + h(k₁ + 2k₂ + 2k₃ + k₄)/6, with k₁ = f(xₙ, yₙ), k₂ = f(xₙ + h/2, yₙ + hk₁/2), k₃ = f(xₙ + h/2, yₙ + hk₂/2), k₄ = f(xₙ + h, yₙ + hk₃).

Can it solve second-order equations?

Not directly; it solves one first-order equation. A second-order equation must first be rewritten as a system of two first-order equations, which this tool does not handle.

Why does it report that the solution blew up?

Some equations really go to infinity at a finite x: y' = y², y(0) = 1 has the solution 1/(1 − x), which is infinite at x = 1. The solver stops when y is no longer a finite number.

More in Math

All tools in this category: Math ·Updated November 4, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.