Skip to content
MoneyDeck

Differential Equation Solver

Solve first- and second-order ODEs numerically with Euler or Runge–Kutta

Updated · Free, no signup

Use x and y; for second order write y′ as yp (or y'). Supports ^, sqrt, sin, cos, exp, ln.

Leave blank if unknown. Used only to show the error; it is ignored if it does not solve your equation and initial value.

y at the end point

3.43655949

Exact y at the end point

3.43656366

Absolute error at the end

0.0000041686

Number of steps

10

Step size used

0.1

Method

Runge–Kutta 4 (RK4)
  • Runge–Kutta 4 (RK4) with h = 0.1 is off by 0.000004169 at x = 1. Halving h cuts the error by about 16×.

Numerical solution y(x)

Step-by-step values

StepxyExact y|Error|
00110
10.11.1103416671.1103418361.695e-7
20.21.2428051421.2428055163.746e-7
30.31.3997169941.3997176156.21e-7
40.41.583648481.5836493959.151e-7
50.51.7974412771.7974425410.000001264
60.62.0442359242.0442376010.000001677
70.72.3275032532.3275054150.000002162
80.82.6510791272.6510818570.00000273
90.93.0192028283.0192062220.000003395
1013.4365594883.4365636570.000004169

About the Differential Equation Solver

This differential equation solver approximates the solution of an initial value problem step by step. Enter a first-order equation y′ = f(x, y) — such as x + y, −2xy or y(1 − y) — or a second-order equation y″ = f(x, y, y′) such as −y or −0.5y′ − 4y, give the starting values, choose a step size and an end point, and it marches the solution forward using Euler’s method, Heun’s improved Euler method or the classic fourth-order Runge–Kutta method (RK4).

It is built for differential equations and numerical-methods students who need to check an Euler or RK4 table by hand, and for engineers and scientists modelling growth, cooling, motion, circuits or oscillators where no simple closed-form answer exists. The full step table, the graph and the final value are shown together.

If you know the exact solution, type it in the optional field and the calculator reports the error at every step, which makes it easy to see how much more accurate RK4 is than Euler and how the error shrinks as the step size gets smaller. Second-order equations are solved by rewriting them as a system of two first-order equations.

With the default inputs, the y at the end point is 3.43655949. Change any value above to recalculate instantly.

How to use the differential equation solver

  1. 1Choose first-order (y′ = …) or second-order (y″ = …).
  2. 2Type the right-hand side using x, y and, for second order, yp for y′.
  3. 3Enter the initial values x₀, y(x₀) and, if needed, y′(x₀).
  4. 4Pick a method, a step size h and the x value to solve up to.
  5. 5Optionally enter the exact solution to see the error, then read the table and graph.

Formula and method

Euler: yₙ₊₁ = yₙ + h·f(xₙ, yₙ) · RK4: yₙ₊₁ = yₙ + (h/6)(k₁ + 2k₂ + 2k₃ + k₄)

All three methods start at (x₀, y₀) and take steps of width h. Euler’s method follows the slope at the start of each step, so its error per unit length shrinks only in proportion to h (first order). Heun’s method averages the slope at the start and at an Euler-predicted end point (second order, error ∝ h²). RK4 combines four slopes — k₁ = f(xₙ, yₙ), k₂ = f(xₙ + h/2, yₙ + h·k₁/2), k₃ = f(xₙ + h/2, yₙ + h·k₂/2), k₄ = f(xₙ + h, yₙ + h·k₃) — for fourth-order accuracy (error ∝ h⁴).

A second-order equation y″ = f(x, y, y′) is converted into the first-order system u₁ = y, u₂ = y′ with u₁′ = u₂ and u₂′ = f(x, u₁, u₂), and the same method is applied to both components at once. The number of steps is (x_end − x₀) ÷ h rounded to a whole number, and h is adjusted slightly so the last step lands exactly on x_end.

h
Step size
xₙ, yₙ
Approximate solution after n steps
f(x, y)
Right-hand side — the slope y′ (or y″ for second order)
k₁…k₄
Slope estimates used by Runge–Kutta

Worked examples

y′ = x + y, y(0) = 1, RK4 with h = 0.1 to x = 1

The exact solution is y = 2eˣ − x − 1, so y(1) = 2e − 2 ≈ 3.4365637. Ten RK4 steps give 3.4365594, an error of only about 4 × 10⁻⁶.

Same problem with Euler’s method

Euler’s method follows the slope at the start of each step and undershoots this convex solution: after 10 steps it reaches about 3.18748, an error of roughly 0.249 — about 60,000 times larger than RK4.

Harmonic oscillator y″ = −y, y(0) = 0, y′(0) = 1

The exact solution is y = sin x, which returns to 0 with slope −1 at x = π. RK4 with 31 steps (h ≈ 0.1013) lands within about 3 × 10⁻⁶ of both values.

Logistic growth y′ = 0.5·y·(1 − y/100), y(0) = 10, to x = 10

With carrying capacity 100, the exact solution 100 ÷ (1 + 9e^(−0.5x)) gives about 94.2826 at x = 10, and 20 RK4 steps of 0.5 give 94.2823 — within 0.0003.

Frequently asked questions

What is Euler’s method?+

Euler’s method approximates an ODE solution by repeatedly stepping along the tangent line: yₙ₊₁ = yₙ + h·f(xₙ, yₙ). It is simple and good for learning, but its error is proportional to the step size, so it needs very small steps for accuracy.

Why is Runge–Kutta (RK4) more accurate?+

RK4 samples the slope four times per step and takes a weighted average, cancelling error terms up to fourth order. Halving the step size cuts RK4’s error by about 16 times, versus only 2 times for Euler.

How do I solve a second-order differential equation numerically?+

Rewrite it as two first-order equations: let u₁ = y and u₂ = y′, so u₁′ = u₂ and u₂′ = f(x, u₁, u₂). Then apply Euler or RK4 to both at once. This calculator does that automatically; you only need y(x₀) and y′(x₀).

How do I choose the step size?+

Start with something like 0.1 and halve it until the answer stops changing in the digits you care about. Smaller steps are more accurate but need more evaluations; stiff equations (very fast decay) may need tiny steps with these explicit methods.

Does this give the exact (symbolic) solution?+

No — it computes a numerical approximation at discrete points. If you know the exact solution, enter it to compare. Separable and linear first-order equations often have closed-form solutions you can find by hand.

What does it mean when the solution blows up?+

Some equations, such as y′ = y², have solutions that go to infinity in finite time, and others involve division by zero. The solver stops when values become undefined or enormous and tells you where that happened.

Related tools