TExcelTAD
Home › Differential Equations › Linear Systems in Matrix Form

Linear Systems in Matrix Form

A linear system of first-order ODEs has the form

x′(t)=P(t) x(t)+f(t),\mathbf{x}'(t) = P(t)\,\mathbf{x}(t) + \mathbf{f}(t),

where P(t)P(t) is an n×nn \times n matrix and f(t)\mathbf{f}(t) a vector. Matrix notation turns the theory of linear equations into linear algebra: superposition becomes "solutions form a vector space", and independence becomes a determinant. Review matrices and determinants in Linear Algebra & Matrix Theory if needed.

Writing a system as a matrix equation

x1′=3x1−x2+etx2′=2x1+t2x2⟺x′=[3−12t2]x+[et0].\begin{aligned} x_1' &= 3x_1 - x_2 + e^t \\ x_2' &= 2x_1 + t^2 x_2 \end{aligned} \quad\Longleftrightarrow\quad \mathbf{x}' = \begin{bmatrix} 3 & -1 \\ 2 & t^2 \end{bmatrix}\mathbf{x} + \begin{bmatrix} e^t \\ 0 \end{bmatrix}.

In NumPy, the right-hand side of such a system for a solver is one line: P(t) @ x + f(t).

python · try it yourself
import numpy as np
from scipy.integrate import solve_ivp

P = lambda t: np.array([[3.0, -1.0], [2.0, t**2]])
f = lambda t: np.array([np.exp(t), 0.0])
sol = solve_ivp(lambda t, x: P(t) @ x + f(t), (0, 1), [1.0, 0.0], rtol=1e-10, atol=1e-12)
print("x(1) =", np.round(sol.y[:, -1], 6))
x(1) = [18.044715 15.764877]

The structure of solutions

For the homogeneous system x′=P(t)x\mathbf{x}' = P(t)\mathbf{x}:

  1. Superposition: any linear combination of solutions is a solution.
  2. If x1,…,xn\mathbf{x}_1, \dots, \mathbf{x}_n are nn linearly independent solutions, every solution is x=c1x1+⋯+cnxn\mathbf{x} = c_1\mathbf{x}_1 + \dots + c_n\mathbf{x}_n.
  3. Put them as columns of the fundamental matrix X(t)=[x1⋯xn]X(t) = [\mathbf{x}_1 \cdots \mathbf{x}_n]. Then the general solution is x=X(t)c\mathbf{x} = X(t)\mathbf{c}, and the initial condition x(t0)=b\mathbf{x}(t_0) = \mathbf{b} gives c=X(t0)−1b\mathbf{c} = X(t_0)^{-1}\mathbf{b}.
  4. The solutions are independent exactly when the Wronskian det⁡X(t)≠0\det X(t) \ne 0.

For the nonhomogeneous system, x=xp+X(t)c\mathbf{x} = \mathbf{x}_p + X(t)\mathbf{c}, as always.

Checking a fundamental matrix

For x′=[1141]x\mathbf{x}' = \begin{bmatrix} 1 & 1 \\ 4 & 1 \end{bmatrix}\mathbf{x}, the functions x1=e3t[12]\mathbf{x}_1 = e^{3t}\begin{bmatrix} 1 \\ 2 \end{bmatrix} and x2=e−t[1−2]\mathbf{x}_2 = e^{-t}\begin{bmatrix} 1 \\ -2 \end{bmatrix} are solutions (you will see where they come from in The Eigenvalue Method).

python · try it yourself
import sympy as sp

t = sp.symbols("t")
A = sp.Matrix([[1, 1], [4, 1]])
X = sp.Matrix([[sp.exp(3*t), sp.exp(-t)], [2*sp.exp(3*t), -2*sp.exp(-t)]])
print("X' - A X =", sp.simplify(X.diff(t) - A * X))
print("Wronskian det X =", sp.simplify(X.det()))
c = X.subs(t, 0).solve(sp.Matrix([3, 2]))              # x(0) = (3, 2)
print("c =", list(c), " x(t) =", list(sp.simplify(X * c)))
X' - A X = Matrix([[0, 0], [0, 0]])
Wronskian det X = -4*exp(2*t)
c = [2, 1]  x(t) = [(2*exp(4*t) + 1)*exp(-t), 2*(2*exp(4*t) - 1)*exp(-t)]

Abel's formula

The Wronskian of a fundamental matrix satisfies W′=tr⁡P(t) WW' = \operatorname{tr}P(t)\,W, so W(t)=W(t0)exp⁡(∫t0ttr⁡P ds)W(t) = W(t_0)\exp\left(\int_{t_0}^t \operatorname{tr}P\,ds\right). In the example tr⁡A=2\operatorname{tr}A = 2 and indeed W=−4e2tW = -4e^{2t}. Since an exponential is never zero, WW is either always zero or never zero.

In software

  • Linear(ized) systems x′=Ax+Bu\mathbf{x}' = A\mathbf{x} + B\mathbf{u} are the "state-space models" of control engineering, used by autopilots, robot controllers and Kalman filters in phone GPS.
  • Libraries like scipy.signal.StateSpace and MATLAB's ss store exactly the matrices AA, BB (and output matrices CC, DD).

Exercises

Exercise 1: Matrix form

Write x′=x+2y−cos⁡tx' = x + 2y - \cos t, y′=−3xy' = -3x in matrix form.

Answer

x′=[12−30]x+[−cos⁡t0]\mathbf{x}' = \begin{bmatrix} 1 & 2 \\ -3 & 0 \end{bmatrix}\mathbf{x} + \begin{bmatrix} -\cos t \\ 0 \end{bmatrix}.

Solution

Rows of the matrix are the coefficients of xx and yy in each equation; everything else goes into f\mathbf{f}.

Exercise 2: Wronskian by Abel

A 3×33 \times 3 system x′=Ax\mathbf{x}' = A\mathbf{x} has tr⁡A=−5\operatorname{tr}A = -5 and W(0)=2W(0) = 2. What is W(1)W(1)?

Answer

W(1)=2e−5W(1) = 2e^{-5}.

Solution

W(t)=W(0)etr⁡(A) tW(t) = W(0)e^{\operatorname{tr}(A)\,t}.

Exercise 3: Initial values (code)

With the fundamental matrix of the lesson, find the solution with x(0)=(1,0)\mathbf{x}(0) = (1, 0).

Answer

x=12e3t(1,2)+12e−t(1,−2)\mathbf{x} = \frac{1}{2}e^{3t}(1, 2) + \frac{1}{2}e^{-t}(1, -2).

Solution
python · try it yourself
import sympy as sp
t = sp.symbols("t")
X = sp.Matrix([[sp.exp(3*t), sp.exp(-t)], [2*sp.exp(3*t), -2*sp.exp(-t)]])
print(list(X.subs(t, 0).solve(sp.Matrix([1, 0]))))
[1/2, 1/2]

Test yourself

A fundamental matrix of x′=Ax\mathbf{x}' = A\mathbf{x} has as its columns…

  1. the eigenvalues
  2. nn linearly independent solutions
  3. the rows of AA
  4. the initial conditions

If X(t)X(t) is a fundamental matrix, the solution with x(0)=b\mathbf{x}(0) = \mathbf{b} is…

  1. X(t)bX(t)\mathbf{b}
  2. X(t)X(0)−1bX(t)X(0)^{-1}\mathbf{b}
  3. X(0)bX(0)\mathbf{b}
  4. bet\mathbf{b}e^t

By Abel's formula the Wronskian of x′=Ax\mathbf{x}' = A\mathbf{x} is…

  1. constant
  2. W(0)etr⁡(A)tW(0)e^{\operatorname{tr}(A)t}
  3. det⁡A\det A
  4. W(0)edet⁡(A)tW(0)e^{\det(A)t}