Ordinary differential equations

Nature rarely tells us a quantity directly. It tells us how the quantity changes. A differential equation is that rule of change.

⏱ 25 minNeeds: Chapters 1–23 simulations
In plain words

"A hot cup of tea cools faster when it is much hotter than the room." That sentence is an equation: the rate of change of temperature is proportional to the temperature difference. A differential equation connects an unknown function with its derivatives. Solving it means finding the function — the whole cooling curve — from the rule alone.

You will learn
Level 1 · basicWhat an ODE is; the simplest one; direction fields Level 2 · standardOscillators, the SIR model, IVP vs BVP Level 3 · advancedExistence and uniqueness; phase plane
Simplest example first · a tank filling at a constant rate

Water flows into a tank at 2 litres per minute, and at time $0$ it holds 1 litre. The rule of change is the ODE $y'(t) = 2$ with initial condition $y(0) = 1$. Its solution is a straight line: $y(t) = 1 + 2t$. Check: the derivative of $1 + 2t$ is $2$ ✓, and at $t = 0$ it gives $1$ ✓. A different starting amount gives a parallel line — the ODE fixes the slope, the initial condition picks which line. If instead $y' = 0$ (tap closed), the level never changes; if $y' = t$ (tap opened gradually), the solution is the parabola $y = t^2/2 + y(0)$.

1. What is an ODE?

Definition · Ordinary differential equation

An ordinary differential equation (ODE) is an equation involving an unknown function $y(t)$ of one variable and some of its derivatives, e.g. $F(t, y, y', y'', \dots, y^{(n)}) = 0$. Its order is that of the highest derivative. It is linear if it has the form $a_n(t)y^{(n)} + \dots + a_1(t)y' + a_0(t)y = g(t)$; otherwise it is nonlinear. A solution on an interval $I$ is a function that satisfies the equation at every $t \in I$.

Boyce, DiPrima & Meade, Elementary Differential Equations and Boundary Value Problems, 11th ed., Wiley (2017), chapter 1 "Introduction".

"Ordinary" means one independent variable. When the unknown depends on several variables (space and time) the equation contains partial derivatives and is a PDE (Partial Differential Equation) — Chapter 7.

EquationOrderLinear?Models
$y' = ky$1yesbank interest, radioactive decay, bacteria
$y' = r y\,(1 - y/K)$1no ($y^2$ term)population with limited resources
$T' = -k\,(T - T_{\text{room}})$1yesNewton's law of cooling
$m y'' + c y' + k y = 0$2yesspring, shock absorber, RLC (Resistor–Inductor–Capacitor) circuit
$\theta'' + \frac{g}{L}\sin\theta = 0$2nopendulum

2. Solving the simplest ODE

Example · exponential growth and decay

Solve $y' = ky$ with $y(0) = y_0$. Separate variables: $\frac{dy}{y} = k\,dt$. Integrate: $\ln|y| = kt + C$. So $$y(t) = y_0\, e^{kt}.$$ Check: $y' = k y_0 e^{kt} = k y$ ✓. For $k < 0$ this is decay; the half-life is $\ln 2/|k|$. Every linear ODE with constant coefficients is solved by exponentials — that is why $e$ is everywhere.

Notice that the ODE alone has infinitely many solutions $Ce^{kt}$. The extra fact $y(0) = y_0$ — an initial condition — picks one. An ODE together with initial conditions is an initial value problem (IVP).

3. Direction fields: seeing solutions without solving

Animation: solution curves are drawn from different starting values, each following the arrows of a direction field.
Watch: Every solution follows the arrows. Different starting values give different curves, but the same law.

A first-order ODE $y' = f(t, y)$ tells you the slope of the solution at every point $(t, y)$. Draw a short dash with that slope at many points: this is a direction field. Solutions are curves that follow the dashes everywhere.

Direction field explorerclick anywhere to start a solution there
Click on the field to drop an initial condition y(t₀) = y₀.
Each curve is computed with the RK4 method of Chapter 6, forwards and backwards from the point you click. Notice: curves never cross. That is the uniqueness theorem below in action. For the logistic model, $y = 0$ and $y = 3$ are equilibria (slope zero) — one repels, one attracts.
Theorem · Existence and uniqueness (Picard–Lindelöf)

Consider $y' = f(t, y)$, $y(t_0) = y_0$. If $f$ and $\partial f/\partial y$ are continuous in a rectangle $|t - t_0| \le a$, $|y - y_0| \le b$, then there is an interval $|t - t_0| \le h$ (with $0 < h \le a$) on which the initial value problem has exactly one solution.

Boyce, DiPrima & Meade (2017), chapter 2, "The Existence and Uniqueness Theorem"; Coddington & Levinson, Theory of Ordinary Differential Equations, McGraw-Hill (1955), chapter 1.
Why the conditions matter

$y' = 3y^{2/3}$, $y(0) = 0$ has two solutions: $y = 0$ and $y = t^3$. Here $\partial f/\partial y = 2y^{-1/3}$ blows up at $y = 0$, so the theorem does not apply. A physical model with non-unique solutions usually means something is missing from the model.

4. Second-order equations: oscillators

Animation: a swinging pendulum and its angle drawn against time.
Watch: A pendulum and its angle $\theta(t)$, the solution of $\theta'' = -\frac{g}{L}\sin\theta$. Full case study in Chapter 19.

Newton's second law (force = mass × acceleration) is second order, because acceleration is the second derivative of position. A mass on a spring with friction obeys $$m\,y'' + c\,y' + k\,y = 0, \qquad y(0) = y_0,\ y'(0) = v_0.$$ Two initial conditions are needed: where the mass starts and how fast it is moving. Trying $y = e^{rt}$ gives the characteristic equation $mr^2 + cr + k = 0$, whose roots decide the behaviour: complex roots → oscillation that dies out (underdamped), a double root → critically damped, two real roots → overdamped.

The damped oscillatorm = 1; adjust stiffness and friction
position y(t)decay envelope
Critical damping is at $c = 2\sqrt{k}$. Car shock absorbers are tuned near it: the car settles quickly without bouncing. The same equation, with inductance, resistance and capacitance, describes an RLC circuit.

Any $n$-th order ODE can be rewritten as a system of $n$ first-order ODEs. With $v = y'$: $y' = v$, $v' = -(c v + k y)/m$. This is how computers handle them (Chapter 6), in vector form $\mathbf u' = \mathbf F(t, \mathbf u)$.

5. Systems: the SIR epidemic model

Split a population into Susceptible, Infected and Recovered fractions. Infection happens when S meets I; recovery happens at a constant rate: $$S' = -\beta S I, \qquad I' = \beta S I - \gamma I, \qquad R' = \gamma I.$$ This model (Kermack & McKendrick, Proc. R. Soc. Lond. A 115, 1927, 700–721) was used throughout the COVID-19 pandemic. The basic reproduction number $R_0 = \beta/\gamma$ decides whether an outbreak grows ($R_0 > 1$).

SIR epidemic1% infected at day 0
S susceptibleI infectedR recovered
Lower $\beta$ (masks, distancing) flattens the red curve. The inverse question — given the observed infection curve, what are $\beta$ and $\gamma$? — is an inverse problem, a classic use of PINNs (Physics-Informed Neural Networks).

6. Initial vs boundary value problems

An IVP (Initial Value Problem) gives all conditions at one starting time: "the ball is thrown from here with this velocity". A boundary value problem (BVP) gives conditions at two ends of a region: "a cable is fixed at both poles; what shape does it hang in?" For example $$-u''(x) = f(x),\quad 0 < x < 1, \qquad u(0) = 0,\ u(1) = 0$$ models the steady temperature in a rod with heat source $f$ and ends held at 0. BVPs may have one, none or many solutions; e.g. $u'' + \pi^2 u = 0$, $u(0) = u(1) = 0$ has all solutions $C\sin(\pi x)$.

Boyce, DiPrima & Meade (2017), chapter 10 "Partial Differential Equations and Fourier Series", section on two-point boundary value problems.
ODEs in SciML

Physics-informed neural networks (Chapter 16) solve ODEs and BVPs by training a network $u_\theta(t)$ so that $u_\theta' - f(t, u_\theta) \approx 0$. Neural ODEs (Chen, Rubanova, Bettencourt & Duvenaud, NeurIPS 2018) go the other way: they learn the right-hand side $f$ as a neural network from data, $\mathbf u' = \mathrm{NN}_\theta(\mathbf u)$. Parameter estimation — finding $\beta, \gamma$ or a cooling rate $k$ from measurements — is the inverse problem at the heart of many applications.

7. Try it in Python

import numpy as np
import matplotlib.pyplot as plt

def sir(u, beta=0.35, gamma=0.1):
    S, I, R = u
    return np.array([-beta*S*I, beta*S*I - gamma*I, gamma*I])

def rk4(f, u0, t):                       # classical Runge-Kutta (Chapter 6)
    u = np.zeros((len(t), len(u0))); u[0] = u0
    for n in range(len(t) - 1):
        h = t[n+1] - t[n]
        k1 = f(u[n]); k2 = f(u[n] + h/2*k1); k3 = f(u[n] + h/2*k2); k4 = f(u[n] + h*k3)
        u[n+1] = u[n] + h/6*(k1 + 2*k2 + 2*k3 + k4)
    return u

t = np.linspace(0, 160, 801)
u = rk4(sir, np.array([0.99, 0.01, 0.0]), t)
for k, name in enumerate("SIR"):
    plt.plot(t, u[:, k], label=name)
plt.xlabel("days"); plt.ylabel("fraction"); plt.legend(); plt.grid(alpha=.3)
plt.title("SIR model, R0 = 3.5"); plt.show()
print("peak infected fraction: %.3f on day %.0f" % (u[:, 1].max(), t[u[:, 1].argmax()]))

What is the order of $y''' + y\,y' = \sin t$, and is it linear?

Right: the highest derivative is $y'''$, and the product $y\,y'$ makes it nonlinear.

How many initial conditions does $m y'' + c y' + k y = 0$ need for a unique solution?

Right — an $n$-th order equation needs $n$ conditions: here position $y(0)$ and velocity $y'(0)$.

Key takeaways

Further reading