ODE Solver

Solve first-order ordinary differential equations dy/dx = f(x, y) numerically with the classic 4th-order Runge–Kutta method — set an initial condition, integrate forward or backward, and get a solution table plus a plot of the integral curve.

Use x and y as variables. Operators: + − * / ^; functions sin cos tan asin acos atan exp log ln sqrt abs; constants pi, e. Example: -y + sin(x)

Presets:

solution y(x)initial point (x₀, y₀)

How it works

This tool uses the classical Runge–Kutta method (RK4). Starting from the initial point (x₀, y₀), it advances one step h at a time, sampling the slope f(x, y) four times per step:

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₃), then yₙ₊₁ = yₙ + h·(k₁ + 2k₂ + 2k₃ + k₄)/6.

RK4 is a 4th-order method: roughly speaking, halving the step size cuts the error by a factor of about 16 — so even a few hundred steps give excellent accuracy for smooth equations. Setting x₁ < x₀ integrates backward along the curve. The solver stops with a message if the solution becomes non-finite (a singularity or blow-up), instead of silently returning garbage.

Frequently asked questions

How accurate is the result?

Very, for smooth equations: RK4's error scales like h⁴, so doubling the steps shrinks the error ~16×. Try the y′ = y example — with 200 steps the computed e differs from the true value only in the 9th decimal place. Sharp spikes or stiff equations may need more steps.

Can it solve second-order ODEs?

Not directly yet. A second-order equation can always be rewritten as a first-order system (for y″ = F, set u = y, v = y′ so u′ = v and v′ = F) — system support is on the roadmap.

What happens if the solution blows up?

The solver checks every step: if a slope evaluation hits a singularity (e.g. a division by zero) or the value diverges to infinity/NaN, it stops and tells you which step failed instead of plotting nonsense.

Which functions can I use in f(x, y)?

All the usual suspects: + − * / ^ (^ is right-associative), parentheses, unary minus, sin cos tan asin acos atan exp log ln sqrt abs, constants pi and e, and the variables x and y. The expression is parsed by a safe hand-written parser — no eval anywhere.