TExcelTAD
Home › Calculus Essentials › Separable Equations

Separable Equations

A separable equation is a first-order differential equation whose right side splits into "a function of xx times a function of yy". You move everything with yy to one side, everything with xx 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

dydx=g(x)⋅h(y)\frac{dy}{dx} = g(x) \cdot h(y)

Treat dy/dxdy/dx like a fraction, divide by h(y)h(y) and multiply by dxdx:

dyh(y)=g(x) dx∫dyh(y)=∫g(x) dx+C\begin{aligned} \frac{dy}{h(y)} &= g(x)\,dx \\ \int \frac{dy}{h(y)} &= \int g(x)\,dx + C \end{aligned}

Then solve for yy if you can. A worked example, dy/dx=2xy2dy/dx = 2xy^2:

dyy2=2x dx−1y=x2+Cy=−1x2+C\begin{aligned} \frac{dy}{y^2} &= 2x\,dx \\ -\frac{1}{y} &= x^2 + C \\ y &= -\frac{1}{x^2 + C} \end{aligned}

Note: Dividing by h(y)h(y) silently assumes h(y)≠0h(y) \ne 0. Any value y0y_0 with h(y0)=0h(y_0) = 0 is a constant solution (an equilibrium) that the formula may miss. For dy/dx=2xy2dy/dx = 2xy^2, the solution y=0y = 0 is not of the form −1/(x2+C)-1/(x^2 + C) for any CC, so write it down separately.

SymPy recognises separable equations and solves them the same way:

python · try it yourself
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 y(0)=1y(0) = 1 the constant is C=−1C = -1, giving y=−1/(x2−1)=1/(1−x2)y = -1/(x^2 - 1) = 1/(1 - x^2). That solution blows up at x=1x = 1: 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 y′=kyy' = ky: the rate of change is proportional to the amount.

dyy=k dt⇒ln⁡∣y∣=kt+C⇒y=y0⋅ekt\frac{dy}{y} = k\,dt \quad\Rightarrow\quad \ln\lvert y \rvert = kt + C \quad\Rightarrow\quad y = y_0 \cdot e^{kt}

k>0k > 0 means growth (compound interest, unchecked populations), k<0k < 0 means decay (radioactivity, a drug leaving the bloodstream). For decay, the half-life is the time for yy to halve: ekT=12e^{kT} = \frac{1}{2} gives T=ln⁡2/∣k∣T = \ln 2 / \lvert k \rvert.

Quantity Model Typical kk
Money at 5% continuous interest y′=0.05yy' = 0.05y 0.05 per year
Carbon-14 y′=−kyy' = -ky ln⁡2/5730≈0.000121\ln 2 / 5730 \approx 0.000121 per year
Caffeine in the body y′=−kyy' = -ky ln⁡2/5≈0.139\ln 2 / 5 \approx 0.139 per hour

Newton's law of cooling

A hot object cools at a rate proportional to the gap between its temperature TT and the room temperature TaT_a:

dTdt=−k(T−Ta)dTT−Ta=−k dt⇒T(t)=Ta+(T0−Ta)⋅e−kt\begin{aligned} &\frac{dT}{dt} = -k(T - T_a) \\ &\frac{dT}{T - T_a} = -k\,dt \quad\Rightarrow\quad T(t) = T_a + (T_0 - T_a) \cdot e^{-kt} \end{aligned}

The gap T−TaT - T_a 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?

python · try it yourself
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 50/7050/70: 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 KK:

dPdt=r⋅P⋅(1−PK)\frac{dP}{dt} = r \cdot P \cdot \left(1 - \frac{P}{K}\right)

It is separable (partial fractions on the left side) and its solution is the S-shaped curve P(t)=K/(1+Ae−rt)P(t) = K / (1 + Ae^{-rt}) with A=(K−P0)/P0A = (K - P_0)/P_0. Equilibria: P=0P = 0 and P=KP = K. Let's check SymPy's answer against a numeric solver:

python · try it yourself
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 lr=lr0⋅e−kt\text{lr} = \text{lr}_0 \cdot e^{-kt}.
  • Smoothing toward a target: a camera that follows a player with x′=−k(x−target)x' = -k(x - \text{target}) 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 σ(z)=1/(1+e−z)\sigma(z) = 1/(1 + e^{-z}) used in logistic regression is the logistic solution with r=1r = 1, K=1K = 1.

Next: equations that are not separable but are linear, solved with an integrating factor.

Exercises

Exercise 1: Separate and integrate

Solve dy/dx=x/ydy/dx = x/y with y(0)=3y(0) = 3 (take y>0y > 0).

Answer

y=x2+9y = \sqrt{x^2 + 9}.

Solution
y dy=x dxy22=x22+Cy2=x2+2C;y(0)=3  ⇒  2C=9y=x2+9(positive root because y(0)>0)check: y′=xx2+9=xy ✓\begin{aligned} y\,dy &= x\,dx \\ \frac{y^2}{2} &= \frac{x^2}{2} + C \\ y^2 &= x^2 + 2C; \qquad y(0) = 3 \;\Rightarrow\; 2C = 9 \\ y &= \sqrt{x^2 + 9} && \text{(positive root because } y(0) > 0\text{)} \\ \text{check: } y' &= \frac{x}{\sqrt{x^2 + 9}} = \frac{x}{y} \ \checkmark \end{aligned}

Exercise 2: Half-life

A medicine has a half-life of 6 hours. A patient has 400 mg in the blood at t=0t = 0. 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
k=ln⁡2/6≈0.1155 per hour,y(t)=400⋅e−kt=400⋅(12)t/6y(15)=400⋅(12)2.5=400/5.657≈70.7 mg400⋅(12)t/6=50  ⇒  (12)t/6=18=(12)3  ⇒  t=18 h\begin{aligned} &k = \ln 2 / 6 \approx 0.1155\ \text{per hour}, \qquad y(t) = 400 \cdot e^{-kt} = 400 \cdot \left(\tfrac{1}{2}\right)^{t/6} \\ &y(15) = 400 \cdot \left(\tfrac{1}{2}\right)^{2.5} = 400 / 5.657 \approx 70.7\ \text{mg} \\ &400 \cdot \left(\tfrac{1}{2}\right)^{t/6} = 50 \;\Rightarrow\; \left(\tfrac{1}{2}\right)^{t/6} = \tfrac{1}{8} = \left(\tfrac{1}{2}\right)^3 \;\Rightarrow\; t = 18\ \text{h} \end{aligned}
python · try it yourself
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
gap(t)=158⋅e−ktgap(10)=98  ⇒  e−10k=98/158gap(30)=158⋅(98/158)3=158⋅0.2386≈37.7T(30)=22+37.7≈59.7 ∘C\begin{aligned} \text{gap}(t) &= 158 \cdot e^{-kt} \\ \text{gap}(10) &= 98 \;\Rightarrow\; e^{-10k} = 98/158 \\ \text{gap}(30) &= 158 \cdot (98/158)^3 = 158 \cdot 0.2386 \approx 37.7 \\ T(30) &= 22 + 37.7 \approx 59.7\ {}^\circ\text{C} \end{aligned}

You don't even need kk: three 10-minute steps each multiply the gap by the same factor 98/15898/158.

Exercise 4: Missing equilibrium

Solve dy/dt=y(1−y)dy/dt = y(1 - y) with SymPy and list the constant solutions the general formula has to be checked for.

Answer

The general solution is y=1/(1+Ce−t)y = 1/(1 + Ce^{-t}) (SymPy may print an equivalent form); the equilibria are y=0y = 0 and y=1y = 1.

Solution

The equilibria are the roots of h(y)=y(1−y)h(y) = y(1 - y). y=1y = 1 is the case C=0C = 0 of the formula, but y=0y = 0 is not reached by any finite CC, so it must be listed separately.

python · try it yourself
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?

  1. y′=x+yy' = x + y
  2. y′=x2sin⁡(y)y' = x^2 \sin(y)
  3. y′=sin⁡(xy)y' = \sin(xy)
  4. y′=x−y2y' = x - y^2

A substance decays with y′=−0.2yy' = -0.2y (tt in days). What is its half-life?

  1. 0.2 days
  2. 5 days
  3. About 3.47 days
  4. About 1.39 days

In Newton's law of cooling T′=−k(T−Ta)T' = -k(T - T_a), what decays exponentially?

  1. The temperature TT itself
  2. The gap T−TaT - T_a between the object and the room
  3. The constant kk
  4. The room temperature