TExcelTAD
Home › Differential Equations › Separable Equations

Separable Equations

An equation is separable if the right-hand side factors into a function of xx times a function of yy:

dydx=f(x) g(y).\frac{dy}{dx} = f(x)\,g(y).

Then all the yy's can be moved to one side and all the xx'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 g(y)≠0g(y) \ne 0, divide by it and integrate both sides with respect to xx:

∫1g(y) dydx dx=∫f(x) dx⟹∫dyg(y)=∫f(x) dx+C.\int \frac{1}{g(y)}\,\frac{dy}{dx}\,dx = \int f(x)\,dx \quad\Longrightarrow\quad \int \frac{dy}{g(y)} = \int f(x)\,dx + C.

The left integral used the substitution rule, which is what the informal "multiply by dxdx" shorthand means. Afterwards, solve for yy if you can; sometimes you can only give the solution implicitly.

Do not forget the constant solutions: wherever g(y0)=0g(y_0) = 0, the constant y=y0y = y_0 is a solution, and dividing by g(y)g(y) loses it.

Example: y′=xyy' = xy

Separate: dyy=x dx\frac{dy}{y} = x\,dx. Integrate: ln⁡∣y∣=x22+C\ln\lvert y\rvert = \frac{x^2}{2} + C. Exponentiate: y=±eCex2/2=Dex2/2y = \pm e^{C}e^{x^2/2} = De^{x^2/2}, where DD can be any nonzero number, and D=0D = 0 restores the lost constant solution y=0y = 0. So the general solution is y=Dex2/2y = De^{x^2/2} for any real DD.

python · try it yourself
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 y′=x21+y2y' = \frac{x^2}{1 + y^2}, separating gives (1+y2) dy=x2 dx(1 + y^2)\,dy = x^2\,dx, so

y+y33=x33+C.y + \frac{y^3}{3} = \frac{x^3}{3} + C.

Solving this cubic for yy is possible but ugly; the implicit form is the honest answer. With y(0)=0y(0) = 0 we get C=0C = 0, i.e. 3y+y3=x33y + y^3 = x^3. Numerically we can still evaluate yy at any xx by solving the cubic, and compare with a numerical ODE solver:

python · try it yourself
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 KK is P′=rP(1−PK)P' = rP\left(1 - \frac{P}{K}\right). It is separable (the right side depends only on PP), and partial fractions give

P(t)=K1+(KP0−1)e−rt.P(t) = \frac{K}{1 + \left(\frac{K}{P_0} - 1\right)e^{-rt}}.
python · try it yourself
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 P=0P = 0 and P=KP = K are where rP(1−P/K)=0rP(1 - P/K) = 0. More on this in Population Models and Harvesting.

In software

  • Exponential decay (y′=−kyy' = -ky, 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: σ(t)\sigma(t) is the logistic solution with K=1K = 1, r=1r = 1, P0=12P_0 = \frac{1}{2}.

Exercises

Exercise 1: Solve by separation

Solve y′=2xyy' = \frac{2x}{y}, y(0)=3y(0) = 3.

Answer

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

Solution

y dy=2x dxy\,dy = 2x\,dx, so y22=x2+C\frac{y^2}{2} = x^2 + C. At x=0x = 0: 92=C\frac{9}{2} = C. Then y2=2x2+9y^2 = 2x^2 + 9, and the positive root matches y(0)=3y(0) = 3.

Exercise 2: Lost solutions

Find all constant solutions of y′=(y2−4)cos⁡xy' = (y^2 - 4)\cos x.

Answer

y=2y = 2 and y=−2y = -2.

Solution

A constant yy has y′=0y' = 0, which for all xx requires y2−4=0y^2 - 4 = 0. Dividing by y2−4y^2 - 4 during separation would lose exactly these two solutions.

Exercise 3: Doubling time (code)

A culture follows P′=0.3P(1−P/1000)P' = 0.3P(1 - P/1000) with P(0)=50P(0) = 50. When does it reach 500 (half the capacity)? Check with SymPy.

Answer

t=ln⁡190.3≈9.815t = \frac{\ln 19}{0.3} \approx 9.815.

Solution

P=500P = 500 means 1+19e−0.3t=21 + 19e^{-0.3t} = 2, so e−0.3t=119e^{-0.3t} = \frac{1}{19} and t=ln⁡190.3t = \frac{\ln 19}{0.3}. SymPy writes the same number as 10ln⁡19310\ln\sqrt[3]{19}.

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

  1. y′=x+yy' = x + y
  2. y′=ex+yy' = e^{x + y}
  3. y′=sin⁡(xy)y' = \sin(xy)
  4. y′=x2+y2y' = x^2 + y^2

When separating y′=f(x)g(y)y' = f(x)g(y), what can be lost?

  1. Nothing
  2. The constant solutions where g(y)=0g(y) = 0
  3. All solutions with y>0y > 0
  4. The constant of integration

The solution of y′=xyy' = xy is…

  1. y=Dex2/2y = De^{x^2/2}
  2. y=x2/2+Cy = x^2/2 + C
  3. y=Dexy = De^x
  4. y=Cxy = Cx