TExcelTAD
Home › Differential Equations › Nonhomogeneous Systems

Nonhomogeneous Systems

A system with an external input,

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

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 f\mathbf{f} is a constant vector b\mathbf{b} and AA is invertible, the constant xp=−A−1b\mathbf{x}_p = -A^{-1}\mathbf{b} solves the system (its derivative is 0 and Axp+b=0A\mathbf{x}_p + \mathbf{b} = \mathbf{0}). If every eigenvalue of AA has negative real part, all solutions converge to it.

Example: two rooms. Room temperatures T1T_1, T2T_2 exchange heat with each other and with the outside at 5 °C, and room 1 has a heater:

T1′=−0.3(T1−T2)−0.1(T1−5)+2,T2′=0.3(T1−T2)−0.2(T2−5).T_1' = -0.3(T_1 - T_2) - 0.1(T_1 - 5) + 2, \qquad T_2' = 0.3(T_1 - T_2) - 0.2(T_2 - 5).
python · try it yourself
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 f(t)=aekt\mathbf{f}(t) = \mathbf{a}e^{kt} or acos⁡ωt+bsin⁡ωt\mathbf{a}\cos\omega t + \mathbf{b}\sin\omega t, guess the same form with unknown vectors. For f=aekt\mathbf{f} = \mathbf{a}e^{kt} with kk not an eigenvalue: xp=uekt\mathbf{x}_p = \mathbf{u}e^{kt} gives ku=Au+ak\mathbf{u} = A\mathbf{u} + \mathbf{a}, so

u=(kI−A)−1a.\mathbf{u} = (kI - A)^{-1}\mathbf{a}.

Variation of parameters

With the fundamental matrix etAe^{tA}, the solution with x(0)=x0\mathbf{x}(0) = \mathbf{x}_0 is

x(t)=etAx0+∫0te(t−s)A f(s) ds.\mathbf{x}(t) = e^{tA}\mathbf{x}_0 + \int_0^t e^{(t-s)A}\,\mathbf{f}(s)\,ds.

It works for any continuous f\mathbf{f}. Read it as: the initial state evolves freely, and each input f(s) ds\mathbf{f}(s)\,ds received at time ss evolves freely for the remaining time t−st - s. This is the vector version of the Green's function formula.

python · try it yourself
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

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), 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 A=[0110]A = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} has eigenvalues ±1\pm 1, and k=2k = 2 is not one of them, so the particular solution is ue2t\mathbf{u}e^{2t} with u=(2I−A)−1(1,0)=(23,13)\mathbf{u} = (2I - A)^{-1}(1, 0) = \left(\frac{2}{3}, \frac{1}{3}\right).

In software

  • Building energy simulators (EnergyPlus and friends) solve large versions of the two-room model, with weather and occupancy as the forcing f(t)\mathbf{f}(t).
  • 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 x′=−x+y+1x' = -x + y + 1, y′=−2y+4y' = -2y + 4.

Answer

(3,2)(3, 2).

Solution

y′=0y' = 0 gives y=2y = 2; then −x+2+1=0-x + 2 + 1 = 0 gives x=3x = 3. The matrix is triangular with eigenvalues −1-1 and −2-2, so the equilibrium is stable.

Exercise 2: Exponential forcing

Find a particular solution of x′=[100−1]x+[11]e3t\mathbf{x}' = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}\mathbf{x} + \begin{bmatrix} 1 \\ 1 \end{bmatrix}e^{3t}.

Answer

xp=(12,14)e3t\mathbf{x}_p = \left(\frac{1}{2}, \frac{1}{4}\right)e^{3t}.

Solution

u=(3I−A)−1(1,1)=(12,14)\mathbf{u} = (3I - A)^{-1}(1, 1) = \left(\frac{1}{2}, \frac{1}{4}\right) because 3I−A=diag⁡(2,4)3I - A = \operatorname{diag}(2, 4).

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 (12.23,8.88)(12.23, 8.88) after 10 and (14.07,10.44)(14.07, 10.44) after 40, approaching the equilibrium (14.09,10.45)(14.09, 10.45).

Solution

Use x(t)=xeq+etA(x0−xeq)\mathbf{x}(t) = \mathbf{x}_{\text{eq}} + e^{tA}(\mathbf{x}_0 - \mathbf{x}_{\text{eq}}), the variation-of-parameters formula for constant forcing.

python · try it yourself
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 x′=Ax+b\mathbf{x}' = A\mathbf{x} + \mathbf{b} with constant b\mathbf{b} and invertible AA, the equilibrium is…

  1. AbA\mathbf{b}
  2. −A−1b-A^{-1}\mathbf{b}
  3. b\mathbf{b}
  4. 0\mathbf{0}

In x(t)=etAx0+∫0te(t−s)Af(s) ds\mathbf{x}(t) = e^{tA}\mathbf{x}_0 + \int_0^t e^{(t-s)A}\mathbf{f}(s)\,ds, the integral is…

  1. the homogeneous solution
  2. the response to the input, starting from rest
  3. zero
  4. the eigenvalues

For forcing aekt\mathbf{a}e^{kt}, the guess uekt\mathbf{u}e^{kt} fails when…

  1. k=0k = 0
  2. kk is an eigenvalue of AA
  3. a=0\mathbf{a} = \mathbf{0}
  4. AA is symmetric