Nonhomogeneous Systems
A system with an external input,
has the familiar structure: general solution = homogeneous solution + one particular solution. This lesson gives three ways to find the particular one: a constant equilibrium, undetermined coefficients, and the general variation of parameters formula with the matrix exponential.
Constant forcing: the equilibrium
If is a constant vector and is invertible, the constant solves the system (its derivative is 0 and ). If every eigenvalue of has negative real part, all solutions converge to it.
Example: two rooms. Room temperatures , exchange heat with each other and with the outside at 5 °C, and room 1 has a heater:
import numpy as np
A = np.array([[-0.4, 0.3], [0.3, -0.5]])
b = np.array([0.1 * 5 + 2, 0.2 * 5])
x_eq = np.linalg.solve(A, -b)
print("eigenvalues:", np.round(np.linalg.eigvals(A), 4))
print("equilibrium temperatures:", np.round(x_eq, 3))eigenvalues: [-0.1459 -0.7541]
equilibrium temperatures: [14.091 10.455]
Both eigenvalues are negative, so the rooms settle at these temperatures from any starting state.
Undetermined coefficients
For forcing such as or , guess the same form with unknown vectors. For with not an eigenvalue: gives , so
Variation of parameters
With the fundamental matrix , the solution with is
It works for any continuous . Read it as: the initial state evolves freely, and each input received at time evolves freely for the remaining time . This is the vector version of the Green's function formula.
import numpy as np
from scipy.linalg import expm
from scipy.integrate import quad_vec, solve_ivp
A = np.array([[0.0, 1.0], [-2.0, -2.0]])
f = lambda s: np.array([0.0, np.sin(3 * s) + 1.0])
x0 = np.array([1.0, 0.0])
t = 2.0
integral, _ = quad_vec(lambda s: expm((t - s) * A) @ f(s), 0, t)
x_formula = expm(t * A) @ x0 + integral
sol = solve_ivp(lambda s, x: A @ x + f(s), (0, t), x0, rtol=1e-11, atol=1e-13)
print("formula: ", np.round(x_formula, 8))
print("solve_ivp:", np.round(sol.y[:, -1], 8))formula: [ 0.52371847 -0.48113934]
solve_ivp: [ 0.52371847 -0.48113934]
Example with SymPy
import sympy as sp
t = sp.symbols("t")
x, y = sp.symbols("x y", cls=sp.Function)
eqs = [sp.Eq(x(t).diff(t), y(t) + sp.exp(2 * t)), sp.Eq(y(t).diff(t), x(t))]
for s in sp.dsolve(eqs, ics={x(0): 0, y(0): 0}):
print(sp.simplify(s))Eq(x(t), ((4*exp(t) - 3)*exp(2*t) - 1)*exp(-t)/6)
Eq(y(t), ((2*exp(t) - 3)*exp(2*t) + 1)*exp(-t)/6)
Here has eigenvalues , and is not one of them, so the particular solution is with .
In software
- Building energy simulators (EnergyPlus and friends) solve large versions of the two-room model, with weather and occupancy as the forcing .
- The integral formula is the basis of "exponential integrators" for stiff problems and of the discretization of control systems.
Exercises
Exercise 1: Equilibrium
Find the equilibrium of , .
Answer
.
Solution
gives ; then gives . The matrix is triangular with eigenvalues and , so the equilibrium is stable.
Exercise 2: Exponential forcing
Find a particular solution of .
Answer
.
Solution
because .
Exercise 3: Room temperatures over time (code)
In the two-room model, start both rooms at 5 °C. What are the temperatures after 10 and after 40 time units?
Answer
About after 10 and after 40, approaching the equilibrium .
Solution
Use , the variation-of-parameters formula for constant forcing.
import numpy as np
from scipy.linalg import expm
A = np.array([[-0.4, 0.3], [0.3, -0.5]]); b = np.array([2.5, 1.0])
xe = np.linalg.solve(A, -b); x0 = np.array([5.0, 5.0])
for t in (10, 40):
print(t, np.round(xe + expm(t * A) @ (x0 - xe), 3))10 [12.234 8.883]
40 [14.068 10.435]
Test yourself
For with constant and invertible , the equilibrium is…
In , the integral is…
- the homogeneous solution
- the response to the input, starting from rest
- zero
- the eigenvalues
For forcing , the guess fails when…
- is an eigenvalue of
- is symmetric