Premium apps Part of Proofline

ODE Solver (Runge–Kutta)

Solve y′ = f(t, y) and systems with adaptive RK45 or RK4: table, plots and CSV.

One equation per line: y' = expression or dy/dt = expression. Right-hand sides may use the independent variable, every state variable and the parameters. Use + − * / ^, implicit products (2x), sin, cos, tan, exp, ln (natural log), log (base 10), sqrt, abs, pi and e. Angles are in radians.

One value per state variable at the start time, e.g. x = 1, v = 0.

More options

Optional constants used in the equations, e.g. a = 1.1, b = 0.4.

Relative error allowed per step; the absolute tolerance is 1/100 of it.

Default: 1/1000 of the interval.

Equally spaced times in the table, plot and CSV (start and end included).

Try an example: Exponential decay y′ = −k·y · Harmonic oscillator as a system · Lotka–Volterra predator and prey · Logistic growth with RK4 · Damped pendulum

More about this tool

How it works

Type a differential equation or a system such as x′ = v, v′ = −x with initial values and parameters, and get the solution table, a plot of every variable, a phase portrait for two variables and a CSV download. Uses the adaptive Dormand–Prince RK45 method with error control or classical fixed-step RK4, and reports steps and function evaluations. Part of the Proofline math notebook.

  • Right-hand sides are read by Proofline’s own expression parser (no eval) and may use the independent variable, all state variables and the parameters.
  • RK45: Dormand–Prince 5(4) embedded pair with local extrapolation and FSAL; the step is accepted when the RMS of error/(atol + rtol·|y|) ≤ 1 and adapted by 0.9·err^(−1/5), limited to a factor 0.2…5.
  • RK4: classical fourth-order Runge–Kutta with a fixed step.
  • Both methods shorten the step before each output time so the table holds computed values, not interpolations.
  • Verified against exact solutions (exponential decay, harmonic oscillator) and the conserved quantity of the Lotka–Volterra system.

Explicit Runge–Kutta methods are not suited to stiff systems (very different time scales): the step size collapses and the solver stops with a message. Tolerances bound the error per step, not the global error.

Sources

Part of Proofline

Related tools

Solve differential equations with Runge–Kutta

Type y′ = f(t, y) or a system with initial values and get a solution table, plots, a phase portrait and a CSV from RK45 or RK4.

What it is for

An initial value problem describes how something changes, such as a cooling cup, a swinging pendulum or two competing populations, and asks where it ends up. Most of these equations have no closed-form solution, so you integrate them numerically.

Write one equation per line, either as y' = -k*y or dy/dt = -k*y. Give an initial value for every variable, optional parameters such as k = 0.5, and the time span. The default method is Dormand–Prince RK45, which adapts its step size to a tolerance. Classical RK4 with a fixed step is there for teaching and comparison.

The tool is meant for non-stiff problems. Stiff systems, such as chemical kinetics with very different time scales, need implicit solvers it does not have.

Worked example

The Lorenz system: enter

x' = sigma*(y - x)
y' = x*(rho - z) - y
z' = x*y - beta*z

with initial values x=1, y=1, z=1, parameters sigma=10, rho=28, beta=2.6666667, end time 2 and 201 output points. RK45 returns x = −8.1735001, y = −9.562024013 and z = 24.62070198 at t = 2, using 276 accepted steps, 4 rejected steps and 1,681 function evaluations. The plot shows the three variables, and the table and CSV hold all 201 rows.

The built-in harmonic oscillator example (x′ = v, v′ = −ω²x with ω = 2, run for two periods from 0 to 2π) ends at x = 0.9999999967 and v = −7.1·10⁻¹⁰. The exact answer is 1 and 0. That gap of a few billionths is the real error at the default tolerance of 10⁻⁸.

How to read the result

  • Metrics give the value of each variable at the end time and the work done: steps, rejected steps (RK45) and evaluations of the right-hand side.
  • Solution over time plots every variable against the independent variable.
  • Phase portrait appears for two variables. A closed loop, as in the Lotka–Volterra example, means a periodic solution. A spiral into the centre means damping.
  • Solution table shows up to 101 rows. The CSV has every output point.
  • A warning appears when the integration stops early, for example when the solution blows up in finite time. The table then ends where the solver gave up.

Tips and common mistakes

  • Every state variable needs exactly one equation and one initial value. Parameters must not reuse those names.
  • Write a second-order equation as two first-order ones: θ″ = −(g/L)·sin θ becomes theta' = w and w' = -g/L*sin(theta).
  • The tolerance limits the error per step, not the total. For long runs, lower it (10⁻¹⁰) and check that the answer stays the same.
  • RK4 with too large a step can look smooth and still be wrong. Halve the step and compare.
  • Output points only control the table. RK45 still chooses its own internal steps between them.
  • ln is the natural logarithm and log is base 10. Angles are in radians.

FAQ

Which method should I choose?

RK45 for almost everything: it controls its error and reports rejected steps. Choose RK4 when an assignment asks for a fixed step, or to see how the error shrinks by about 16 times when you halve the step.

Why do I get "the step size became too small"?

The problem is probably stiff or has a singularity, such as y′ = y², which blows up at t = 1 for y(0) = 1. Shorten the interval or rethink the model.

How was the solver checked?

Against exact solutions (exponential decay, harmonic oscillator over ten periods) and against the conserved quantity of the Lotka–Volterra system, which stays constant to 10⁻⁷ along the computed orbit at a tolerance of 10⁻¹⁰.

Can I go backwards in time?

No. The end time must be larger than the start time.

Guide last updated:

For scripts and AI agents

  • JSON API: POST https://prooflineodesolver.usefulweb.site/api/v1/calculate (same calculation as this page)
  • Interface description: OpenAPI 3.1 · AI guide: llms.txt
  • MCP server (Streamable HTTP): https://prooflineodesolver.usefulweb.site/mcp · tool name proofline_ode_solver
Example request
curl -s -X POST https://prooflineodesolver.usefulweb.site/api/v1/calculate \
  -H 'content-type: application/json' \
  -d '{"equations":"y' = -k*y","initial":"y = 1","parameters":"k = 0.5","tEnd":10}'
Feedback · ideas & bug reports welcome