Separable Equations
A separable equation is a first-order differential equation whose right side splits into "a function of times a function of ". You move everything with to one side, everything with to the other, and integrate both sides. This one trick solves exponential growth and decay, Newton's law of cooling and the logistic model.
The method
An equation is separable when it can be written as
Treat like a fraction, divide by and multiply by :
Then solve for if you can. A worked example, :
Note: Dividing by silently assumes . Any value with is a constant solution (an equilibrium) that the formula may miss. For , the solution is not of the form for any , so write it down separately.
SymPy recognises separable equations and solves them the same way:
import sympy as sp
x = sp.symbols("x")
y = sp.Function("y")
ode = sp.Eq(y(x).diff(x), 2 * x * y(x)**2)
print(sp.classify_ode(ode)[0])
print(sp.dsolve(ode))
print(sp.dsolve(ode, ics={y(0): 1}))separable
Eq(y(x), -1/(C1 + x**2))
Eq(y(x), -1/(x**2 - 1))
With the constant is , giving . That solution blows up at : a nonlinear equation can reach infinity in finite time even though its right side looks harmless.
Growth and decay
The most important separable equation is : the rate of change is proportional to the amount.
means growth (compound interest, unchecked populations), means decay (radioactivity, a drug leaving the bloodstream). For decay, the half-life is the time for to halve: gives .
| Quantity | Model | Typical |
|---|---|---|
| Money at 5% continuous interest | 0.05 per year | |
| Carbon-14 | per year | |
| Caffeine in the body | per hour |
Newton's law of cooling
A hot object cools at a rate proportional to the gap between its temperature and the room temperature :
The gap decays exponentially. Suppose a mug of tea starts at 90 °C in a 20 °C room and reads 70 °C after 5 minutes. When does it reach a drinkable 60 °C?
import math
Ta, T0 = 20, 90
# 70 - 20 = (90 - 20) e^(-5k) -> k = ln(70/50) / 5
k = math.log(70 / 50) / 5
print(f"k = {k:.4f} per minute")
t60 = math.log((T0 - Ta) / (60 - Ta)) / k
print(f"60 °C after {t60:.2f} minutes")
for t in [0, 5, 10, 20, 40]:
T = Ta + (T0 - Ta) * math.exp(-k * t)
print(f"t = {t:2d} min: {T:5.1f} °C")k = 0.0673 per minute
60 °C after 8.32 minutes
t = 0 min: 90.0 °C
t = 5 min: 70.0 °C
t = 10 min: 55.7 °C
t = 20 min: 38.2 °C
t = 40 min: 24.7 °C
Every 5 minutes the gap shrinks by the same factor : 70 → 50 → 35.7 → … above room temperature. The tea never quite reaches 20 °C; the gap only approaches 0.
The logistic equation
Real populations can't grow forever. The logistic model adds a capacity :
It is separable (partial fractions on the left side) and its solution is the S-shaped curve with . Equilibria: and . Let's check SymPy's answer against a numeric solver:
import numpy as np
from scipy.integrate import solve_ivp
r, K, P0 = 0.8, 1000, 10
A = (K - P0) / P0
exact = lambda t: K / (1 + A * np.exp(-r * t))
sol = solve_ivp(lambda t, P: r * P * (1 - P / K), (0, 12), [P0],
t_eval=[0, 3, 6, 9, 12], rtol=1e-9, atol=1e-9)
for t, p in zip(sol.t, sol.y[0]):
print(f"t = {t:4.1f}: numeric {p:8.2f} formula {exact(t):8.2f}")t = 0.0: numeric 10.00 formula 10.00
t = 3.0: numeric 100.19 formula 100.19
t = 6.0: numeric 551.04 formula 551.04
t = 9.0: numeric 931.17 formula 931.17
t = 12.0: numeric 993.34 formula 993.34
In software
- Exponential decay everywhere: cache entries with a decaying score, "hot" rankings (Hacker News-style scores divided by an age term), exponential moving averages of frame times, learning-rate schedules with .
- Smoothing toward a target: a camera that follows a player with is Newton's cooling with "temperature" replaced by position. Its exact solution gives the frame-rate-independent formula in easing and smoothing and damping.
- Logistic curves: the sigmoid used in logistic regression is the logistic solution with , .
Next: equations that are not separable but are linear, solved with an integrating factor.
Exercises
Exercise 1: Separate and integrate
Solve with (take ).
Answer
.
Solution
Exercise 2: Half-life
A medicine has a half-life of 6 hours. A patient has 400 mg in the blood at . How much is left after 15 hours, and when does it drop below 50 mg?
Answer
About 70.7 mg after 15 h; it drops below 50 mg after 18 hours.
Solution
import math
k = math.log(2) / 6
print(f"after 15 h: {400 * math.exp(-k * 15):.1f} mg")
print(f"below 50 mg at t = {math.log(400 / 50) / k:.1f} h")after 15 h: 70.7 mg
below 50 mg at t = 18.0 h
Exercise 3: Cooling backwards
A cake comes out of a 180 °C oven into a 22 °C kitchen. After 10 minutes it is 120 °C. What is its temperature after 30 minutes?
Answer
About 59.7 °C.
Solution
You don't even need : three 10-minute steps each multiply the gap by the same factor .
Exercise 4: Missing equilibrium
Solve with SymPy and list the constant solutions the general formula has to be checked for.
Answer
The general solution is (SymPy may print an equivalent form); the equilibria are and .
Solution
The equilibria are the roots of . is the case of the formula, but is not reached by any finite , so it must be listed separately.
import sympy as sp
t = sp.symbols("t")
y = sp.Function("y")
Y = sp.symbols("Y")
print(sp.dsolve(sp.Eq(y(t).diff(t), y(t) * (1 - y(t)))))
print("equilibria:", sp.solve(Y * (1 - Y), Y))Eq(y(t), 1/(C1*exp(-t) + 1))
equilibria: [0, 1]
Test yourself
Which equation is separable?
A substance decays with ( in days). What is its half-life?
- 0.2 days
- 5 days
- About 3.47 days
- About 1.39 days
In Newton's law of cooling , what decays exponentially?
- The temperature itself
- The gap between the object and the room
- The constant
- The room temperature