TExcelTAD
Home › Differential Equations › Introduction to Systems of ODEs

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.

x1′=f1(t,x1,x2,…,xn)    ⋮xn′=fn(t,x1,x2,…,xn)orx′=f(t,x).\begin{aligned} x_1' &= f_1(t, x_1, x_2, \dots, x_n) \\ &\;\;\vdots \\ x_n' &= f_n(t, x_1, x_2, \dots, x_n) \end{aligned} \qquad\text{or}\qquad \mathbf{x}' = \mathbf{f}(t, \mathbf{x}).

Every higher-order equation is a system

Introduce the derivatives as new unknowns. For y′′+3y′+2y=sin⁡ty'' + 3y' + 2y = \sin t, set x1=yx_1 = y and x2=y′x_2 = y':

x1′=x2,x2′=sin⁡t−2x1−3x2.x_1' = x_2, \qquad x_2' = \sin t - 2x_1 - 3x_2.

An nnth-order equation becomes nn 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. x′=2xx' = 2x, y′=x+yy' = x + y with x(0)=1x(0) = 1, y(0)=0y(0) = 0. The first equation gives x=e2tx = e^{2t}; then y′−y=e2ty' - y = e^{2t} is linear, and y=e2t−ety = e^{2t} - e^{t}.

Elimination. In x′=yx' = y, y′=−xy' = -x, differentiate the first: x′′=y′=−xx'' = y' = -x. So x=Acos⁡t+Bsin⁡tx = A\cos t + B\sin t and y=x′=−Asin⁡t+Bcos⁡ty = x' = -A\sin t + B\cos t. Elimination turns a system of nn equations into one equation of order nn; for larger systems the matrix methods of the next lessons are better.

python · try it yourself
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 (x1(t),x2(t))(x_1(t), x_2(t)) of a two-dimensional system can be drawn as a curve in the (x1,x2)(x_1, x_2)-plane, the phase plane, with tt as the parameter. For an autonomous system x′=f(x)\mathbf{x}' = \mathbf{f}(\mathbf{x}), the vector f(x)\mathbf{f}(\mathbf{x}) 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).

python · try it yourself
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 x=cos⁡tx = \cos t is a closed loop.

Existence and uniqueness for systems

The theorem of Existence and Uniqueness holds verbatim for systems: if f\mathbf{f} and its partial derivatives in x\mathbf{x} are continuous, each initial condition x(t0)=x0\mathbf{x}(t_0) = \mathbf{x}_0 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 x′=f(x)\mathbf{x}' = \mathbf{f}(\mathbf{x}) each frame.
  • Simulation tools such as Simulink, Modelica and scipy.integrate.solve_ivp all take a first-order system as their input format.

Exercises

Exercise 1: Convert to a system

Write y′′′−y′′+4y=ety''' - y'' + 4y = e^t as a first-order system.

Answer

x1′=x2x_1' = x_2, x2′=x3x_2' = x_3, x3′=et−4x1+x3x_3' = e^t - 4x_1 + x_3.

Solution

With x1=yx_1 = y, x2=y′x_2 = y', x3=y′′x_3 = y'', the equation says y′′′=et+y′′−4yy''' = e^t + y'' - 4y.

Exercise 2: Triangular system

Solve x′=−xx' = -x, y′=x−2yy' = x - 2y, x(0)=1x(0) = 1, y(0)=0y(0) = 0.

Answer

x=e−tx = e^{-t}, y=e−t−e−2ty = e^{-t} - e^{-2t}.

Solution

x=e−tx = e^{-t}. Then y′+2y=e−ty' + 2y = e^{-t} has integrating factor e2te^{2t}: (e2ty)′=et(e^{2t}y)' = e^{t}, so y=e−t+Ce−2ty = e^{-t} + Ce^{-2t} and C=−1C = -1.

Exercise 3: Elimination (code)

Solve x′=yx' = y, y′=4xy' = 4x with x(0)=1x(0) = 1, y(0)=0y(0) = 0, by hand and with SymPy.

Answer

x=cosh⁡2tx = \cosh 2t, y=2sinh⁡2ty = 2\sinh 2t.

Solution

x′′=4xx'' = 4x, so x=Ae2t+Be−2tx = Ae^{2t} + Be^{-2t} with A+B=1A + B = 1 and x′(0)=y(0)=2A−2B=0x'(0) = y(0) = 2A - 2B = 0.

python · try it yourself
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 cosh⁡2t\cosh 2t as 12(e2t+e−2t)\frac{1}{2}(e^{2t} + e^{-2t}).

Test yourself

A fourth-order ODE becomes a first-order system of how many equations?

  1. 1
  2. 2
  3. 4
  4. 8

In the phase plane of an autonomous 2D system, trajectories…

  1. always cross at the origin
  2. never cross (for smooth f\mathbf{f})
  3. are always straight lines
  4. depend on the starting time

Which system describes y′′+y=0y'' + y = 0 with x1=yx_1 = y, x2=y′x_2 = y'?

  1. x1′=x2,x2′=−x1x_1' = x_2, x_2' = -x_1
  2. x1′=−x1,x2′=x2x_1' = -x_1, x_2' = x_2
  3. x1′=x1,x2′=x1x_1' = x_1, x_2' = x_1
  4. x1′=x2,x2′=x1x_1' = x_2, x_2' = x_1