Introduction to Systems of ODEs
Real models rarely have a single unknown. Predators and prey, the three compartments of an epidemic, the position and velocity of a body, the currents in two coupled circuits: each is a system of differential equations, several unknown functions whose rates depend on each other.
Every higher-order equation is a system
Introduce the derivatives as new unknowns. For , set and :
An th-order equation becomes first-order equations. This is why theory and software can focus on first-order systems.
Solving small systems by hand
Some systems decouple or can be solved one equation at a time.
Example. , with , . The first equation gives ; then is linear, and .
Elimination. In , , differentiate the first: . So and . Elimination turns a system of equations into one equation of order ; for larger systems the matrix methods of the next lessons are better.
import sympy as sp
t = sp.symbols("t")
x, y = sp.symbols("x y", cls=sp.Function)
eqs = [sp.Eq(x(t).diff(t), 2 * x(t)), sp.Eq(y(t).diff(t), x(t) + y(t))]
for s in sp.dsolve(eqs, ics={x(0): 1, y(0): 0}):
print(s)Eq(x(t), exp(2*t))
Eq(y(t), exp(2*t) - exp(t))
Solutions as curves in phase space
A solution of a two-dimensional system can be drawn as a curve in the -plane, the phase plane, with as the parameter. For an autonomous system , the vector at each point is the velocity of the solution passing through it. The picture of these arrows is the vector field, and a sketch of typical trajectories is the phase portrait (Two-Dimensional Phase Portraits).
import numpy as np
from scipy.integrate import solve_ivp
f = lambda t, X: [X[1], -X[0]] # x' = y, y' = -x
sol = solve_ivp(f, (0, 2 * np.pi), [1.0, 0.0], t_eval=np.linspace(0, 2 * np.pi, 5), rtol=1e-10, atol=1e-12)
for t, x, y in zip(sol.t, *sol.y):
print(f"t = {t:.3f}: (x, y) = ({x: .4f}, {y: .4f}), x^2 + y^2 = {x*x + y*y:.6f}")t = 0.000: (x, y) = ( 1.0000, 0.0000), x^2 + y^2 = 1.000000
t = 1.571: (x, y) = (-0.0000, -1.0000), x^2 + y^2 = 1.000000
t = 3.142: (x, y) = (-1.0000, 0.0000), x^2 + y^2 = 1.000000
t = 4.712: (x, y) = ( 0.0000, 1.0000), x^2 + y^2 = 1.000000
t = 6.283: (x, y) = ( 1.0000, -0.0000), x^2 + y^2 = 1.000000
The trajectory is the unit circle traversed clockwise: in the phase plane the oscillation is a closed loop.
Existence and uniqueness for systems
The theorem of Existence and Uniqueness holds verbatim for systems: if and its partial derivatives in are continuous, each initial condition has a unique local solution. For autonomous systems, this means trajectories in the phase plane never cross.
In software
- Physics engines store the state of every body (position, orientation, velocity, angular velocity) in one big vector and advance each frame.
- Simulation tools such as Simulink, Modelica and
scipy.integrate.solve_ivpall take a first-order system as their input format.
Exercises
Exercise 1: Convert to a system
Write as a first-order system.
Answer
, , .
Solution
With , , , the equation says .
Exercise 2: Triangular system
Solve , , , .
Answer
, .
Solution
. Then has integrating factor : , so and .
Exercise 3: Elimination (code)
Solve , with , , by hand and with SymPy.
Answer
, .
Solution
, so with and .
import sympy as sp
t = sp.symbols("t"); x, y = sp.symbols("x y", cls=sp.Function)
for s in sp.dsolve([sp.Eq(x(t).diff(t), y(t)), sp.Eq(y(t).diff(t), 4 * x(t))], ics={x(0): 1, y(0): 0}):
print(s)Eq(x(t), exp(2*t)/2 + exp(-2*t)/2)
Eq(y(t), exp(2*t) - exp(-2*t))
SymPy writes as .
Test yourself
A fourth-order ODE becomes a first-order system of how many equations?
- 1
- 2
- 4
- 8
In the phase plane of an autonomous 2D system, trajectories…
- always cross at the origin
- never cross (for smooth )
- are always straight lines
- depend on the starting time
Which system describes with , ?