Skip to main content

RESEARCH & SIMULATION LAB

Differential equation solver for numerical models.

Model first-order ordinary differential equations and two-state systems with Euler, Improved Euler, and RK4. Inspect solution curves, phase plots, and numerical tables directly in your browser.

NUMERICAL OUTPUT

Ready to simulate

Runge–Kutta 4 (RK4)
dy/dx

Set the equation, initial values, interval, and method. Your graph, final values, and table will appear here.

Choose a preset or enter an equation, then run a numerical simulation.

MODEL SETUP

Build the numerical experiment

Examples

METHOD NOTE

Euler is fast but less accurate. Heun improves the slope estimate. RK4 is a strong general-purpose fixed-step method. All outputs are numerical approximations.
01

Choose the model

Enter the right-hand side only, such as -2*y + sin(x). Use x, y, and z with supported functions.

02

Set initial conditions

Specify where the numerical experiment begins, its final x value, and a controlled step size.

03

Inspect the approximation

Compare curves, phase behavior, and tables. Reduce the step size when accuracy needs checking.

METHOD

Euler, Heun and RK4 compared on one example

What does this differential equation solver do?

It solves first-order initial value problems y′ = f(x, y), y(x₀) = y₀, and two-equation systems numerically. It steps forward with a fixed step size h using Euler, Heun (improved Euler) or fourth-order Runge–Kutta (RK4), and shows the solution curve, a phase plot for systems, and a table of values.

Worked example: y′ = y, y(0) = 1, find y(1)

The exact answer is e = 2.718282, so you can see each method's error directly.

  • Euler, h = 0.1 (10 steps): 2.593742, an error of 0.125.
  • Heun, h = 0.1: 2.714081, an error of 0.0042.
  • RK4, h = 0.1: 2.718280, an error of 0.000002.
  • Euler with a smaller step, h = 0.05: 2.653298. Halving h only halves Euler's error, because Euler is a first-order method.

One RK4 step by hand

y₁ = y₀ + h(k₁ + 2k₂ + 2k₃ + k₄) ÷ 6
  1. For y′ = y, y(0) = 1 and h = 0.1: k₁ = f(0, 1) = 1.
  2. k₂ = f(0.05, 1 + 0.05 × 1) = 1.05.
  3. k₃ = f(0.05, 1 + 0.05 × 1.05) = 1.0525.
  4. k₄ = f(0.1, 1 + 0.1 × 1.0525) = 1.10525.
  5. y(0.1) ≈ 1 + 0.1 × (1 + 2.1 + 2.105 + 1.10525) ÷ 6 = 1.105171, against the exact e^0.1 = 1.105171.

How to choose the method and step size

  • Start with RK4: for smooth problems it is far more accurate than Euler for the same number of steps.
  • Run the problem again with half the step size. If the answer barely changes, the step is small enough.
  • Stiff equations (very fast decay next to slow change, such as y′ = −1000y) need tiny steps with these explicit methods; use an implicit solver for those.
  • Higher-order equations, such as y″ + y = 0, can be rewritten as a two-equation system (y′ = v, v′ = −y) and solved here as a system.