Chris Collins

Tools · math

ODE solver and phase portraits

Solve systems of ordinary differential equations with Euler, RK4, or adaptive Dormand–Prince RK45; see time series and phase portraits with direction fields, nullclines, clicked trajectories, classified equilibria, and a rotatable 3-D view. Plus a slope field with Euler's method against the exact solution, and an integrator shoot-out showing energy drift.

Added · updated 14 October 2026

How to use it

Three tabs: Solver & phase plane (any system), Slope field & Euler (one equation dy/dt = g(t, y), step by step) and Energy drift (four integrators racing on a pendulum, a spring, an orbit and a projectile). Each tab has its own address — /tools/ode/#slope, /tools/ode/#energy.

⛶ Full screen (or F) gives the active tab’s main canvas — the phase plane, the slope field or the simulation — the whole screen (the browser’s full screen where it is allowed, otherwise a full-window layer on iPhone); ◫ Panels hides the settings column. Escape leaves.

Solver & phase plane

  • Write the system one equation per line: x' = y, y' = -x - 0.2*y. Higher-order equations are converted for you: θ'' = -sin(θ) - b*θ' creates the states θ and θ′. Any other name = value line is a parameter (parameters may use earlier ones, e.g. L = 2*g). Use t for time; Greek letters work as names. Functions: sin, cos, tan, exp, ln/log, sqrt, abs, sign, min, max, step, and more; ^ is a power.

  • Initial conditions look like θ = 2.5, θ' = 0. Pick a time span and a method:

    • Euler — first order, for seeing why nobody uses it;

    • RK4 — classical fourth-order Runge–Kutta with a fixed step h;

    • RK45 — Dormand–Prince 5(4) with adaptive steps controlled by the relative tolerance (absolute tolerance is 1000× smaller). Use it unless you want to study a fixed-step method.

  • Phase plane: choose the axes. The direction field and the nullclines (where each plotted component’s derivative is zero) are drawn with the other states held at their initial values. Click anywhere to launch a trajectory from that point, forward and optionally backward in time. Drag to pan, scroll to zoom, double-click to refit.

  • Equilibria (autonomous systems only) are found by Newton’s method from a grid of starting points across the visible range. The Jacobian is computed numerically and its eigenvalues (Faddeev–LeVerrier characteristic polynomial, Durand–Kerner roots) classify each point as a node, spiral, saddle, saddle-focus, or centre. A linear centre or a zero eigenvalue means the linearisation cannot decide stability.

  • 3-D: for systems with three or more states (the Lorenz attractor, SIR), tick 3-D and drag to rotate.

  • Export the solution as CSV, or the phase portrait as PNG.

The kind of equilibrium comes from the eigenvalues of the Jacobian matrix; the Matrix transformations tool shows what eigenvectors and complex eigenvalues (rotation with scaling) look like for a single matrix.

Stiff systems (very different time scales) will make RK45 take tiny steps; this tool has no implicit solver.

Slope field & Euler

  • Type the rate dy/dt = g(t, y) using t and y (0.5*y, y*(1 - y), cos(t) - y), or pick one from Equations…. Each short segment shows the slope g(t, y) at that point: every solution curve runs along them.

  • Click the field to start from that point (t₀, y₀), or type t₀, y₀ and the end time T.

  • Δt (slider or box) is Euler’s step: yₙ₊₁ = yₙ + Δt·g(tₙ, yₙ). The orange path is Euler; the dashed curve is the true solution through the same point — the exact formula for the built-in equations (growth, decay, the stiff −3y, logistic, cooling, cos t), otherwise an adaptive RK45 reference curve, labelled as such. The readout gives Euler’s final value, the true one and the error; the table lists the first twelve steps as you would write them by hand.

  • Try dy/dt = −3y with Δt = 1: each step multiplies y by −2 and Euler explodes instead of decaying.

Energy drift

Choose a conservative system — a pendulum (g/L = 1, released from rest), a spring, a planet orbit (GM = 1) or a projectile (g = 9.8) — a step h and how long to run. Four integrators run side by side with the same h:

  • Euler — position and velocity both from the old state;

  • semi-implicit (symplectic) Euler — velocity first, then position with the new velocity;

  • velocity Verlet — the trapezoid-rule cousin used in molecular dynamics and games;

  • RK4 — classical fourth-order Runge–Kutta.

The upper picture shows the system (four pendulums, the orbits, the spring in the (x, v) plane, or height against time) at the time on the slider — press Play to animate. Below, E(t)/E(0) for each: energy should be constant, so any drift is numerical error. The table gives each integrator’s final energy ratio and its largest deviation. Untick an integrator in the legend to rescale the plot.

Body models: pharmacokinetics, a neuron, glucose

Toy model — not physiology. Simulation only. Educational — not a medical device. Not for diagnosis, treatment, monitoring or dosing. The notice shows above the solver whenever the system carries the line # toy model — not physiology, as these three presets do.

  • One-compartment PK (invented drug) — an oral dose absorbed from the gut at rate ka into one well-mixed compartment of volume V and eliminated at ke = ln 2 / t½. The drug and its numbers are invented; nothing here is a dose. The solution matches the Bateman equation C(t) = F·D·ka / (V(ka − ke)) · (e^(−ke·t) − e^(−ka·t)), peaking at t = ln(ka/ke)/(ka − ke). Repeated doses are not modelled (the system has no impulse input); change the initial amount to see proportionality.

  • FitzHugh–Nagumo action potential — a two-variable caricature of the action potential: a fast voltage with positive feedback and a slow recovery. Start a little above the threshold and you get a full spike; a little below and nothing — all-or-nothing. A steady current I = 0.5 makes it fire repeatedly: intensity is coded by frequency, not amplitude. Turn on the nullclines and click the phase plane to find the threshold. (FitzHugh 1961; Nagumo, Arimoto & Yoshizawa 1962.)

  • Minimal glucose model (toy) — shaped like Bergman’s minimal model (Bergman et al. 1979): glucose relaxes towards Gb on its own and faster as insulin action X builds; insulin rises while glucose is above h. The parameters are made up to show the shape; the units are there so the equations read sensibly, not to describe a person.

Companion to chapter 7, Nerves, sensation, and accessible design (the action potential) and chapter 10, Kidneys, gut, and hormones (hormonal loops and drug absorption) of Human Biology for the Medical Maker.

Limits

Explicit solvers only (Euler, RK4, RK45); the energy tab adds semi-implicit Euler and velocity Verlet for its four built-in systems only. The slope field is for one first-order equation; for a spring or anything second order use the solver’s phase plane (or the energy tab). The body models are teaching caricatures: one compartment, two-variable neuron, three-variable glucose; they omit nearly everything that matters clinically.

Related: Linear systems (conditioning), graphing calculator, PID loop simulator (its toy glucose loop shows what sensor and actuator delays do), matrix transformations.

Linking to an example

Share link (under the title) copies a URL that reopens this tool exactly as you have it — every tab’s inputs, with the current tab selected. Opening such a link replaces the inputs this browser had saved for the tool.

Links can also be written by hand. A link without a #tab opens the tab its parameters belong to.

Parameter Meaning Example

example

a book example (list below); other parameters override its values

example=ch19-euler-growth

f

slope field: the rate g(t, y) in dy/dt = g(t, y)

f=y*(1-y)

t0, y0

slope field: the starting point

t0=0&y0=0.1

dt

slope field: Euler’s step Δt

dt=0.25

T

slope field: end time

T=4

ylo, yhi

slope field: the y range shown (otherwise automatic)

ylo=-1&yhi=3

sys

energy drift: pendulum, spring, orbit or projectile

sys=orbit

h

energy drift: the step size

h=0.05

angle

energy drift: pendulum release angle in radians, or spring amplitude

angle=2

v0

energy drift: orbit start speed, or projectile launch speed (m/s)

v0=0.9

tmax

energy drift: how long to run

tmax=60

preset

solver: load a built-in system by name (older links)

preset=Van der Pol

In f, write for multiplication. A + typed straight into an address arrives as a space (that is how URLs work), so a space between two terms is read as a plus: ?f=0.5*y+1 means 0.5y + 1. Links made with *Share link encode everything and need no care.

Examples:

example= What it shows

ch19-euler-growth

dy/dt = 0.5y from y(0) = 1 with Δt = 1: the worked example, 5.0625 against e² ≈ 7.389

ch19-decay

dy/dt = −y: Euler with Δt = 0.5 against the exact decay

ch19-logistic

the logistic equation dy/dt = y(1 − y) from y(0) = 0.1

ch19-unstable

dy/dt = −3y with Δt = 1: each step multiplies by −2 and Euler explodes

ch32-euler-e

y′ = y, y(0) = 1, h = 0.25 to t = 1: Euler gives 2.4414 against e = 2.71828

ch33-logistic

dy/dt = ky(1 − y/K) with k = 0.8, K = 10: the S-curve; raise Δt and Euler peels away

ch19-projectile

a ball thrown up at 20 m/s, h = 0.1 to t = 2: Euler 21.380 m, semi-implicit 19.420 m, Verlet exactly 20.400 m

ch32-shootout

pendulum released at 1 rad, h = 0.1, 60 time units: E(60)/E(0) = 8.12 (Euler), 1.02 (semi-implicit), 0.99999 (RK4)

ch32-orbit

a planet starting at distance 1 with speed 0.9: Euler spirals outward, the symplectic orbits stay closed

ch33-spring

the spring x″ = −x: the exact path in (x, v) is a circle; Euler spirals out

Older links such as ?preset=Van der Pol still open the solver with that built-in system.

Runs entirely in your browser; nothing you type leaves this page.