Substitution: Bernoulli and Homogeneous Equations
Many equations that are neither separable nor linear become one of the two after a change of variables. The idea is the same as substitution in integrals: pick a new unknown , rewrite and in terms of , and hope the new equation is easier. Three substitutions cover most textbook cases.
1. Linear combinations:
Set . Then , which is separable.
Example. . With : , so and .
2. Homogeneous equations:
If the right side depends only on the ratio , set , so and . Then , i.e.
which is separable. (This use of "homogeneous" is unrelated to "homogeneous linear equation"; the name is historical.)
Example. . Then , so , , and .
import sympy as sp
x = sp.symbols("x", positive=True)
y = sp.Function("y")
ode = sp.Eq(y(x).diff(x), (x**2 + y(x)**2) / (x * y(x)))
for s in sp.dsolve(ode):
print(s)Eq(y(x), -x*sqrt(C1 + 2*log(x)))
Eq(y(x), x*sqrt(C1 + 2*log(x)))
SymPy returns both branches of the square root.
3. Bernoulli equations:
For this is nonlinear, but makes it linear. Since , divide the equation by and multiply by :
which the integrating factor solves.
Example. . Here , and . So and .
import numpy as np
from scipy.integrate import solve_ivp
# y(0) = 0.5 -> v(0) = 4 -> C = 3
sol = solve_ivp(lambda x, y: y**3 - y, (0, 2), [0.5], t_eval=[0.5, 1, 2], rtol=1e-10, atol=1e-12)
for xv, yv in zip(sol.t, sol.y[0]):
print(f"x = {xv}: numeric {yv:.8f}, formula {1 / np.sqrt(1 + 3 * np.exp(2 * xv)):.8f}")x = 0.5: numeric 0.33050230, formula 0.33050230
x = 1.0: numeric 0.20776076, formula 0.20776076
x = 2.0: numeric 0.07789843, formula 0.07789843
Which substitution?
| Shape of the equation | Substitution | Result |
|---|---|---|
| separable | ||
| separable | ||
| linear | ||
| none needed | separable |
sp.classify_ode tells you which forms SymPy recognises. Names such as Bernoulli and 1st_homogeneous_coeff_subs_dep_div_indep correspond to rows of this table, but SymPy may also pick a different route: below, it notices that is separable as well as Bernoulli, and it treats as a Riccati equation rather than using our substitution. Several methods often solve the same equation.
import sympy as sp
x = sp.symbols("x")
y = sp.Function("y")
for ode in (sp.Eq(y(x).diff(x) + y(x), y(x)**3),
sp.Eq(y(x).diff(x), (x + y(x))**2)):
print([h for h in sp.classify_ode(ode) if "Integral" not in h][:4])['separable', '1st_exact', 'Bernoulli', '1st_power_series']
['factorable', '1st_rational_riccati', '1st_power_series', 'lie_group']
In software
- The logistic equation is a Bernoulli equation with ; the substitution is how its S-curve formula is usually derived.
- Choosing variables that simplify a model is everyday work in simulation code: scaling to dimensionless variables (Dimensionless Variables) is a substitution, and it often reduces the number of parameters a solver must handle.
Exercises
Exercise 1: Bernoulli by hand
Solve (the logistic equation with ) using .
Answer
.
Solution
, , so . Then gives and .
Exercise 2: Homogeneous
Solve for .
Answer
.
Solution
: , so and . (The equation is also linear, and the integrating factor gives the same answer.)
Exercise 3: Linear combination (code)
Solve , and evaluate . Compare with solve_ivp.
Answer
, so .
Solution
From the lesson, ; gives .
import numpy as np
from scipy.integrate import solve_ivp
sol = solve_ivp(lambda x, y: (x + y)**2, (0, 1), [0.0], rtol=1e-10, atol=1e-12)
print(f"{sol.y[0][-1]:.6f} {np.tan(1) - 1:.6f}")0.557408 0.557408
The solution blows up at , where does.
Test yourself
Which substitution turns into a linear equation?
For , the substitution gives $y' = $…
After substituting in , the equation for is…
- linear