Linear Systems in Matrix Form
A linear system of first-order ODEs has the form
where is an matrix and 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
In NumPy, the right-hand side of such a system for a solver is one line: P(t) @ x + f(t).
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 :
- Superposition: any linear combination of solutions is a solution.
- If are linearly independent solutions, every solution is .
- Put them as columns of the fundamental matrix . Then the general solution is , and the initial condition gives .
- The solutions are independent exactly when the Wronskian .
For the nonhomogeneous system, , as always.
Checking a fundamental matrix
For , the functions and are solutions (you will see where they come from in The Eigenvalue Method).
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 , so . In the example and indeed . Since an exponential is never zero, is either always zero or never zero.
In software
- Linear(ized) systems are the "state-space models" of control engineering, used by autopilots, robot controllers and Kalman filters in phone GPS.
- Libraries like
scipy.signal.StateSpaceand MATLAB'sssstore exactly the matrices , (and output matrices , ).
Exercises
Exercise 1: Matrix form
Write , in matrix form.
Answer
.
Solution
Rows of the matrix are the coefficients of and in each equation; everything else goes into .
Exercise 2: Wronskian by Abel
A system has and . What is ?
Answer
.
Solution
.
Exercise 3: Initial values (code)
With the fundamental matrix of the lesson, find the solution with .
Answer
.
Solution
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 has as its columns…
- the eigenvalues
- linearly independent solutions
- the rows of
- the initial conditions
If is a fundamental matrix, the solution with is…
By Abel's formula the Wronskian of is…
- constant