Separable Equations
An equation is separable if the right-hand side factors into a function of times a function of :
Then all the 's can be moved to one side and all the 's to the other, and both sides integrated. It is the first real solution method of the course, and it covers exponential growth, Newton's law of cooling and the logistic equation.
The method
If , divide by it and integrate both sides with respect to :
The left integral used the substitution rule, which is what the informal "multiply by " shorthand means. Afterwards, solve for if you can; sometimes you can only give the solution implicitly.
Do not forget the constant solutions: wherever , the constant is a solution, and dividing by loses it.
Example:
Separate: . Integrate: . Exponentiate: , where can be any nonzero number, and restores the lost constant solution . So the general solution is for any real .
import sympy as sp
x = sp.symbols("x")
y = sp.Function("y")
ode = sp.Eq(y(x).diff(x), x * y(x))
print(sp.dsolve(ode))
print(sp.classify_ode(ode)[:3])Eq(y(x), C1*exp(x**2/2))
('separable', '1st_exact', '1st_linear')
classify_ode lists the methods SymPy considers applicable; "separable" is among them.
Example: an implicit solution
For , separating gives , so
Solving this cubic for is possible but ugly; the implicit form is the honest answer. With we get , i.e. . Numerically we can still evaluate at any by solving the cubic, and compare with a numerical ODE solver:
import numpy as np
from scipy.integrate import solve_ivp
from scipy.optimize import brentq
sol = solve_ivp(lambda x, y: x**2 / (1 + y**2), (0, 2), [0.0], rtol=1e-10, atol=1e-12)
y_ode = sol.y[0][-1]
y_implicit = brentq(lambda y: 3 * y + y**3 - 8, 0, 3) # x = 2: 3y + y^3 = 8
print(f"ODE solver: {y_ode:.8f}, implicit equation: {y_implicit:.8f}")ODE solver: 1.51274533, implicit equation: 1.51274533
Example: the logistic equation
Population growth with a carrying capacity is . It is separable (the right side depends only on ), and partial fractions give
import sympy as sp
t, r, K, P0 = sp.symbols("t r K P_0", positive=True)
P = K / (1 + (K / P0 - 1) * sp.exp(-r * t))
residual = sp.simplify(P.diff(t) - r * P * (1 - P / K))
print("residual:", residual, " P(0) =", sp.simplify(P.subs(t, 0)))
print("limit as t -> oo:", sp.limit(P, t, sp.oo))residual: 0 P(0) = P_0
limit as t -> oo: K
The constant solutions and are where . More on this in Population Models and Harvesting.
In software
- Exponential decay (, separable) is how game engines fade sounds, damp camera shake and implement "exponential smoothing":
x += (target - x) * (1 - exp(-k * dt))is the exact solution over one frame, so it behaves the same at any frame rate. - Logistic curves model user adoption, the S-shaped learning-rate warm-ups of some training schedules and the sigmoid activation itself: is the logistic solution with , , .
Exercises
Exercise 1: Solve by separation
Solve , .
Answer
.
Solution
, so . At : . Then , and the positive root matches .
Exercise 2: Lost solutions
Find all constant solutions of .
Answer
and .
Solution
A constant has , which for all requires . Dividing by during separation would lose exactly these two solutions.
Exercise 3: Doubling time (code)
A culture follows with . When does it reach 500 (half the capacity)? Check with SymPy.
Answer
.
Solution
means , so and . SymPy writes the same number as .
import sympy as sp
t = sp.symbols("t", positive=True)
P = 1000 / (1 + 19 * sp.exp(-sp.Rational(3, 10) * t))
T = sp.solve(sp.Eq(P, 500), t)[0]
print(T, round(float(T), 3))10*log(19**(1/3)) 9.815
Test yourself
Which equation is separable?
When separating , what can be lost?
- Nothing
- The constant solutions where
- All solutions with
- The constant of integration
The solution of is…