Module contents
Lesson 17 of 20Core 100 min

Linear ODE systems, the matrix exponential and phase portraits

Construct the matrix exponential, classify planar phase portraits, solve systems with inputs using Duhamel, prove Liouville’s formula and discretize continuous systems for state space models.

After this lesson you can

  • Define the matrix exponential by its series and compute it by diagonalization and in the defective case.
  • Solve x′ = Ax and classify planar equilibria by trace and determinant.
  • Solve systems x′ = Ax + Bu with Duhamel’s formula and discretize them by zero-order hold.
  • Prove det(e^{tA}) = e^{t·tr A} and interpret it as volume change.
  • Implement matrix exponential by scaling and squaring and validate against scipy.linalg.expm.

Before you start

Motivation: the one fully solvable case

The previous lesson gave general guarantees (Picard–Lindelöf, Grönwall) and a few tricks for individual equations. Almost no interesting ODE has a closed-form solution. One family, however, is completely solvable: constant-coefficient linear systems, x′=Ax\vb{x}' = \mat{A}\vb{x}. It matters far more than its simplicity suggests:

  • Linearization is looking through A\mat{A}. Near equilibrium any dynamics x′=f(x)\vb{x}' = \vb{f}(\vb{x}) resembles x′=Jx\vb{x}' = \mat{J}\vb{x}, where J\mat{J} is the Jacobian there. Eigenvalue lessons about J\mat{J} apply to pendulums, circuits, ecosystems and control loops. The next lesson makes this a theorem.
  • State space models are linear systems with input. S4 and Mamba, studied in sequence architectures, begin from x′=Ax+Bu\vb{x}' = \mat{A}\vb{x} + \mat{B}u, discretize at step Δ\Delta and obtain a recurrence trained as a convolution. Model memory is determined by eigenvalues of A\mat{A} and step Δ\Delta.
  • Recurrent networks and the Kalman filter have the same linear object in discrete time: xk+1=Fxk\vb{x}_{k+1} = \mat{F}\vb{x}_k. Vanishing or exploding gradients are a spectral issue appearing here in continuous time.
  • Control (LQR, robot stabilization) works with x′=Ax+Bu\vb{x}' = \mat{A}\vb{x} + \mat{B}\vb{u} and determines closed-loop stability from eigenvalue locations.

This lesson does four things. First construct the matrix exponential etAe^{t\mat{A}}, playing the role of eate^{at} for x′=axx' = ax. Then calculate it in the three Jordan-form cases and classify planar phase portraits by trace and determinant. Next solve systems with input (Duhamel’s formula) and prove Liouville’s formula for volume scaling. Finally prepare for computation: exact discretization and numerical matrix exponentiation by scaling and squaring.

From a number to a matrix

For one number, x′=axx' = ax with x(0)=x0x(0) = x_0 has solution x(t)=eatx0x(t) = e^{at}x_0. With nn coupled variables the equation has exactly the same form.

This is the simplest possible first-order ODE and also the destination of any higher-order linear ODE. For example y′′+3y′+2y=0y'' + 3y' + 2y = 0 reduces, with x=(y,y′)\vb{x} = (y, y'), to

x′=[01−2−3]x,\vb{x}' = \begin{bmatrix} 0 & 1 \\ -2 & -3 \end{bmatrix}\vb{x},

and the characteristic polynomial of that A\mat{A} is λ2+3λ+2\lambda^2 + 3\lambda + 2, the same obtained by trying y=eλty = e^{\lambda t} in the second-order equation (the previous lesson’s second-order linear ODE). Eigenvalues of A\mat{A} are the characteristic roots.

Existence, uniqueness and superposition

Proof

Field f(x)=Ax\vb{f}(\vb{x}) = \mat{A}\vb{x} is globally Lipschitz with constant ∥A∥\norm{\mat{A}} because ∥Ax−Ay∥≤∥A∥∥x−y∥\norm{\mat{A}\vb{x} - \mat{A}\vb{y}} \le \norm{\mat{A}}\norm{\vb{x} - \vb{y}}. Picard–Lindelöf gives a unique local solution. It cannot explode in finite time: ∥x(t)∥≤∥x0∥+∥A∥∫0t∥x(s)∥ ⁣ds\norm{\vb{x}(t)} \le \norm{\vb{x}_0} + \norm{\mat{A}}\int_0^t \norm{\vb{x}(s)}\dd s and Grönwall yield ∥x(t)∥≤∥x0∥ e∥A∥∣t∣\norm{\vb{x}(t)} \le \norm{\vb{x}_0}\,e^{\norm{\mat{A}}\abs{t}}, so it remains bounded on every bounded interval and extends to all R\R.

Differentiation is linear: if x\vb{x} and y\vb{y} are solutions and α,β∈R\alpha, \beta \in \R, then (αx+βy)′=αAx+βAy=A(αx+βy)(\alpha\vb{x} + \beta\vb{y})' = \alpha\mat{A}\vb{x} + \beta\mat{A}\vb{y} = \mat{A}(\alpha\vb{x} + \beta\vb{y}). By uniqueness, the solution with initial value αx0+βy0\alpha\vb{x}_0 + \beta\vb{y}_0 is αx+βy\alpha\vb{x} + \beta\vb{y}, so x0↦x(t)\vb{x}_0 \mapsto \vb{x}(t) is linear. It is injective because solutions coinciding at an instant tt coincide forever (uniqueness holds backward too), hence bijective. The solution space is isomorphic to Rn\R^n via x↦x(0)\vb{x} \mapsto \vb{x}(0).

∎

This superposition principle makes the linear case special: solve nn independent initial problems (for example x0=e1,…,en\vb{x}_0 = \vb{e}_1, \dots, \vb{e}_n) and all other solutions are combinations. The matrix with these nn solutions as columns, Φ(t)=[x(1)(t)⋯x(n)(t)]\mat{\Phi}(t) = [\vb{x}^{(1)}(t) \cdots \vb{x}^{(n)}(t)], is the fundamental matrix, and general solution is x(t)=Φ(t)x0\vb{x}(t) = \mat{\Phi}(t)\vb{x}_0. What is Φ(t)\mat{\Phi}(t)?

The matrix exponential

If A\mat{A} were a number, the solution would be etAx0e^{t\mat{A}}\vb{x}_0. We must define etAe^{t\mat{A}}. The exponential power series makes sense for matrices because it uses only sums and products.

Does it converge? Yes, always. Choose a submultiplicative matrix norm (for example one induced by a vector norm), so ∥Ak∥≤∥A∥k\norm{\mat{A}^k} \le \norm{\mat{A}}^k. Then ∑k∥Ak∥/k!≤∑k∥A∥k/k!=e∥A∥<∞\sum_k \norm{\mat{A}^k}/k! \le \sum_k \norm{\mat{A}}^k/k! = e^{\norm{\mat{A}}} < \infty: the series converges absolutely for every A\mat{A} in complete space Rn×n\R^{n\times n} (likewise for Cn×n\C^{n\times n}), and ∥eA∥≤e∥A∥\norm{e^{\mat{A}}} \le e^{\norm{\mat{A}}}. With tAt\mat{A} instead of A\mat{A}, for ∣t∣≤T\abs{t} \le T terms are bounded by (T∥A∥)k/k!(T\norm{\mat{A}})^k/k! independent of tt: by the Weierstrass M-test (uniform convergence), the etAe^{t\mat{A}} series converges uniformly on [−T,T][-T, T], as does its derivative series, so lesson 14’s limit-interchange theorems permit termwise differentiation (an exercise below).

Proof

(3) Since (PAP−1)k=PAkP−1(\mat{P}\mat{A}\mat{P}\inv)^k = \mat{P}\mat{A}^k\mat{P}\inv, take P\mat{P} and P−1\mat{P}\inv outside the series (summation is continuous linear). (4) Likewise: (Ak)⊤=(A⊤)k(\mat{A}^k)\T = (\mat{A}\T)^k. (5) Since A\mat{A} and B\mat{B} commute, the binomial theorem gives (A+B)m=∑j=0m(mj)AjBm−j(\mat{A}+\mat{B})^m = \sum_{j=0}^m \binom{m}{j}\mat{A}^j\mat{B}^{m-j}, hence

eA+B=∑m=0∞∑j=0mAjj!Bm−j(m−j)!=(∑j=0∞Ajj!)(∑l=0∞Bll!)=eAeB.e^{\mat{A}+\mat{B}} = \sum_{m=0}^\infty \sum_{j=0}^m \frac{\mat{A}^j}{j!}\frac{\mat{B}^{m-j}}{(m-j)!} = \Big(\sum_{j=0}^\infty \frac{\mat{A}^j}{j!}\Big)\Big(\sum_{l=0}^\infty \frac{\mat{B}^l}{l!}\Big) = e^{\mat{A}}e^{\mat{B}}.

The second equality is the Cauchy product of two absolutely convergent series. (1) and (2) follow from (5) with commuting tAt\mat{A} and sAs\mat{A}, and B=−A\mat{B} = -\mat{A}.

∎

Condition AB=BA\mat{A}\mat{B} = \mat{B}\mat{A} in (5) is not a technicality. With A=[0100]\mat{A} = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix} and B=A⊤\mat{B} = \mat{A}\T (noncommuting), eAeB=[2111]e^{\mat{A}}e^{\mat{B}} = \begin{bmatrix} 2 & 1 \\ 1 & 1 \end{bmatrix} and eBeA=[1112]e^{\mat{B}}e^{\mat{A}} = \begin{bmatrix} 1 & 1 \\ 1 & 2 \end{bmatrix} already differ, whereas eA+B=[cosh⁡1sinh⁡1sinh⁡1cosh⁡1]≈[1.5431.1751.1751.543]e^{\mat{A}+\mat{B}} = \begin{bmatrix} \cosh 1 & \sinh 1 \\ \sinh 1 & \cosh 1 \end{bmatrix} \approx \begin{bmatrix} 1.543 & 1.175 \\ 1.175 & 1.543 \end{bmatrix} is neither. This reappears as a common mistake.

etAe^{t\mat{A}} solves the system

Proof

By property (1), e(t+h)A−etAh=etA ehA−Ih\frac{e^{(t+h)\mat{A}} - e^{t\mat{A}}}{h} = e^{t\mat{A}}\,\frac{e^{h\mat{A}} - \mat{I}}{h}. It suffices to show the last quotient tends to A\mat{A} as h→0h \to 0. Subtracting A\mat{A} and using the series,

∥ehA−Ih−A∥=∥∑k=2∞hk−1Akk!∥≤∣h∣ ∥A∥2∑k=2∞(∣h∣∥A∥)k−2k!≤∣h∣ ∥A∥2e∣h∣∥A∥→h→00.\Big\|\frac{e^{h\mat{A}} - \mat{I}}{h} - \mat{A}\Big\| = \Big\|\sum_{k=2}^\infty \frac{h^{k-1}\mat{A}^k}{k!}\Big\| \le \abs{h}\,\norm{\mat{A}}^2\sum_{k=2}^\infty \frac{(\abs{h}\norm{\mat{A}})^{k-2}}{k!} \le \abs{h}\,\norm{\mat{A}}^2 e^{\abs{h}\norm{\mat{A}}} \xrightarrow[h\to 0]{} 0.

Thus the derivative is etAAe^{t\mat{A}}\mat{A}, also AetA\mat{A}e^{t\mat{A}} because A\mat{A} commutes with every power of itself. Hence x(t)=etAx0\vb{x}(t) = e^{t\mat{A}}\vb{x}_0 solves the equation and x(0)=x0\vb{x}(0) = \vb{x}_0. It is unique: if y\vb{y} is another solution, z(t)=e−tAy(t)\vb{z}(t) = e^{-t\mat{A}}\vb{y}(t) satisfies z′=−Ae−tAy+e−tAAy=0\vb{z}' = -\mat{A}e^{-t\mat{A}}\vb{y} + e^{-t\mat{A}}\mat{A}\vb{y} = \vb{0}, so z\vb{z} is constant and equal to z(0)=x0\vb{z}(0) = \vb{x}_0, and y(t)=etAx0\vb{y}(t) = e^{t\mat{A}}\vb{x}_0.

∎

The fundamental matrix with Φ(0)=I\mat{\Phi}(0) = \mat{I} is therefore Φ(t)=etA\mat{\Phi}(t) = e^{t\mat{A}}. It is the system’s flow: the motion carrying each point x0\vb{x}_0 to its position tt seconds later. Property (1), e(s+t)A=esAetAe^{(s+t)\mat{A}} = e^{s\mat{A}}e^{t\mat{A}}, says flowing for ss then tt equals flowing for s+ts + t; (2) says it can always be reversed. The next interactive shows its effect on a figure.

InteractiveThe exponential flow transports shapes
Relative area versus tt (logarithmic scale)
  • measured polygon area
  • et tr⁡Ae^{t\,\tr\mat{A}} (Liouville)
  • figure at time tt
  • initial figure
  • paths of four vertices
etA=[0.52−1.341.340.52]e^{t\mat{A}} = \begin{bmatrix} 0.52 & -1.34 \\ 1.34 & 0.52 \end{bmatrix}
Entries of A
1.20
tr⁡A\tr\mat{A}0.60
Current / initial area (measured)2.0544
et tr⁡Ae^{t\,\tr\mat{A}}2.0544
det⁡etA\det e^{t\mat{A}}2.0544
tr⁡A>0\tr\mat{A} > 0: the flow expands area at a constant rate on a logarithmic scale.
A letter F (chosen because it is asymmetric, making flips visible) is transported by etAe^{t\mat{A}}, and trajectories of four vertices follow the equation. Explore examples. With antisymmetric A\mat{A} the figure rotates without deformation. With a nilpotent Jordan block it shears and slides. With a saddle it stretches along one axis and contracts along the other. In each case measured area equals et tr⁡Ae^{t\,\tr\mat{A}} (dashed curve, straight on a log scale). Edit A\mat{A} entries and find a nonzero matrix with zero trace: what happens to area? We prove it in the Liouville section.

How to calculate it: three cases

Defining etAe^{t\mat{A}} by a series is not calculating it. By property (3), bring A\mat{A} to a form where the series sums itself. Jordan form offers three cases, all visible in 2×22\times 2.

Diagonalizable with real eigenvalues

If A=PΛP−1\mat{A} = \mat{P}\mat{\Lambda}\mat{P}\inv with Λ=diag⁡(λ1,…,λn)\mat{\Lambda} = \diag(\lambda_1, \dots, \lambda_n) (diagonalization), then Λk=diag⁡(λik)\mat{\Lambda}^k = \diag(\lambda_i^k) and the series sums entrywise:

etA=P diag⁡(eλ1t,…,eλnt) P−1,x(t)=∑i=1nci eλitvi,c=P−1x0.e^{t\mat{A}} = \mat{P}\,\diag\big(e^{\lambda_1 t}, \dots, e^{\lambda_n t}\big)\,\mat{P}\inv, \qquad \vb{x}(t) = \sum_{i=1}^n c_i\,e^{\lambda_i t}\vb{v}_i, \quad \vb{c} = \mat{P}\inv\vb{x}_0.

Each eigenvector vi\vb{v}_i is a direction the flow does not rotate: on its line dynamics are scalar x′=λixx' = \lambda_i x. In the earlier example A=[01−2−3]\mat{A} = \begin{bmatrix} 0 & 1 \\ -2 & -3 \end{bmatrix} has eigenvalues −1-1 and −2-2 with eigenvectors (1,−1)(1, -1) and (1,−2)(1, -2), and

etA=[2e−t−e−2te−t−e−2t−2e−t+2e−2t−e−t+2e−2t].e^{t\mat{A}} = \begin{bmatrix} 2e^{-t} - e^{-2t} & e^{-t} - e^{-2t} \\ -2e^{-t} + 2e^{-2t} & -e^{-t} + 2e^{-2t} \end{bmatrix}.

Check it equals I\mat{I} at t=0t = 0 and its derivative at 00 is A\mat{A}. Its first row applied to (y0,y0′)(y_0, y'_0) recovers classical solution y(t)=c1e−t+c2e−2ty(t) = c_1e^{-t} + c_2e^{-2t}.

Complex eigenvalues: rotate and scale

A real matrix can have complex eigenvalues, always conjugate pairs α±iβ\alpha \pm i\beta (complex eigenvalues from linear algebra lesson 10). In a suitable real basis A\mat{A} is the block

C=[α−ββα]=αI+βJ,J=[0−110].\mat{C} = \begin{bmatrix} \alpha & -\beta \\ \beta & \alpha \end{bmatrix} = \alpha\mat{I} + \beta\mat{J}, \qquad \mat{J} = \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}.

Since αI\alpha\mat{I} commutes with everything, (5) gives etC=eαteβtJe^{t\mat{C}} = e^{\alpha t}e^{\beta t\mat{J}}. Since J2=−I\mat{J}^2 = -\mat{I}, powers of J\mat{J} repeat with period 4 and the eβtJe^{\beta t\mat{J}} series separates even terms (giving cos⁡βt⋅I\cos\beta t\cdot\mat{I}) from odd terms (giving sin⁡βt⋅J\sin\beta t\cdot\mat{J}): Euler’s formula for a matrix,

etC=eαt[cos⁡βt−sin⁡βtsin⁡βtcos⁡βt].e^{t\mat{C}} = e^{\alpha t}\begin{bmatrix} \cos\beta t & -\sin\beta t \\ \sin\beta t & \cos\beta t \end{bmatrix}.

A rotation at angular speed β\beta and factor eαte^{\alpha t}: solutions are logarithmic spirals entering if α<0\alpha < 0, leaving if α>0\alpha > 0 and closing into circles (ellipses in the original basis) if α=0\alpha = 0. Generally write A=PCP−1\mat{A} = \mat{P}\mat{C}\mat{P}\inv using real and imaginary parts of a complex eigenvector, as in lesson 10’s real-form theorem.

Repeated and defective eigenvalues

When an eigenvector is missing, A\mat{A} reduces only to a Jordan block. For Jλ=[λ10λ]=λI+N\mat{J}_\lambda = \begin{bmatrix} \lambda & 1 \\ 0 & \lambda \end{bmatrix} = \lambda\mat{I} + \mat{N} with N=[0100]\mat{N} = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}, N2=0\mat{N}^2 = \mat{0} and N\mat{N} commutes with λI\lambda\mat{I}, so the etNe^{t\mat{N}} series stops after two terms:

etJλ=eλt (I+tN)=eλt[1t01].e^{t\mat{J}_\lambda} = e^{\lambda t}\,(\mat{I} + t\mat{N}) = e^{\lambda t}\begin{bmatrix} 1 & t \\ 0 & 1 \end{bmatrix}.

A polynomial factor t eλtt\,e^{\lambda t} appears that no diagonalizable solution has. In a block of size mm, Nm=0\mat{N}^m = \mat{0} and the exponential contains powers of tt through tm−1t^{m-1}. Since every real matrix is PJP−1\mat{P}\mat{J}\mat{P}\inv with block J\mat{J}, a general result follows without further calculation.

Read this from the Jordan exponential: tkeαtt^k e^{\alpha t} tends to zero if α<0\alpha < 0 for every kk, because the exponential beats every polynomial, while tkeαtt^k e^{\alpha t} with k≥1k \ge 1 and α=0\alpha = 0 grows unboundedly. Thus shear J0\mat{J}_0 (double defective eigenvalue 00) has solutions escaping linearly even though no eigenvalue has positive real part.

Planar phase portraits

For n=2n = 2 we can see dynamics. A plane point x=(x1,x2)\vb{x} = (x_1, x_2) is a state, solution t↦etAx0t \mapsto e^{t\mat{A}}\vb{x}_0 traces a curve, and all such curves form the system’s portrait.

The origin is always an equilibrium. Portrait shape near it is determined by spectrum of A\mat{A}, and for 2×22\times 2 spectrum depends only on trace and determinant. With τ=tr⁡A\tau = \tr\mat{A} and δ=det⁡A\delta = \det\mat{A}, eigenvalues are λ=τ±τ2−4δ2\lambda = \frac{\tau \pm \sqrt{\tau^2 - 4\delta}}{2}, hence:

Region of (τ,δ)(\tau, \delta) planeEigenvaluesPortrait
δ<0\delta < 0real, opposite signssaddle: unstable
δ>0\delta > 0, τ2>4δ\tau^2 > 4\delta, τ<0\tau < 0real, both negativestable node (sink)
δ>0\delta > 0, τ2>4δ\tau^2 > 4\delta, τ>0\tau > 0real, both positiveunstable node (source)
τ2<4δ\tau^2 < 4\delta, τ<0\tau < 0α±iβ\alpha \pm i\beta, α<0\alpha < 0stable focus: inward spiral
τ2<4δ\tau^2 < 4\delta, τ>0\tau > 0α±iβ\alpha \pm i\beta, α>0\alpha > 0unstable focus: outward spiral
τ=0\tau = 0, δ>0\delta > 0±iβ\pm i\betacenter: closed orbits, stable but not asymptotically
τ2=4δ≠0\tau^2 = 4\delta \ne 0repeated realdegenerate node (one eigenvector) or star node (A=λI\mat{A} = \lambda\mat{I})
δ=0\delta = 0at least one zero eigenvaluenonisolated equilibrium: a line of equilibria (whole plane if A=0\mat{A} = \mat{0})

All fits in the trace–determinant plane: horizontal axis τ\tau, vertical δ\delta, and parabola δ=τ2/4\delta = \tau^2/4 separates nodes below from foci above. The interactive draws the exact portrait with etAx0e^{t\mat{A}}\vb{x}_0 forward and backward in time.

InteractiveThe trace–determinant plane and its phase portrait
(τ,δ)(\tau, \delta) plane
nodonodofocofocosillacentrosestableinestableδ = τ²/4τ
Phase portrait of x′=Ax\vb{x}' = \mat{A}\vb{x}
  • trajectories etAx0e^{t\mat{A}}\vb{x}_0
  • eigenline of larger λ\lambda
  • eigenline of smaller λ\lambda
  • your trajectories
A=[−2.003.00−1.501.00]\mat{A} = \begin{bmatrix} -2.00 & 3.00 \\ -1.50 & 1.00 \end{bmatrix}
Entries of A
τ=tr⁡A\tau = \tr\mat{A}−1.00
δ=det⁡A\delta = \det\mat{A}2.50
τ2−4δ\tau^2 - 4\delta−9.00
Eigenvalues−0.50 ± 1.50 i
Portraitstable focus
Complex eigenvalues α±iβ\alpha \pm i\beta: rotation at frequency β\beta and growth eαte^{\alpha t}. The sign of the trace decides whether the spiral enters or leaves.
Drag point (τ,δ)(\tau, \delta) in the left plane (it snaps to the parabola and axes) or edit A\mat{A}, and inspect the portrait on the right. Dashed orange and aqua lines are eigenlines with real eigenvalues. Explore half-plane δ<0\delta < 0 (saddles), cross the parabola from node to focus and watch trajectories stop being tangent to a line and start rotating. Cross axis τ=0\tau = 0 above the parabola: a stable focus passes through a center and becomes unstable. On the parabola toggle the Jordan block: how do degenerate node and star differ? Click the portrait to launch trajectories and enable particles to see flow.

Classification follows from the three forms above. If x=Py\vb{x} = \mat{P}\vb{y}, orbits of x′=Ax\vb{x}' = \mat{A}\vb{x} are images under P\mat{P} of orbits of y′=P−1APy\vb{y}' = \mat{P}\inv\mat{A}\mat{P}\vb{y}: a linear coordinate change stretches and rotates the portrait without changing qualitative type (hence the figure’s eigenlines are not perpendicular). It suffices to inspect canonical forms:

  • Node and saddle (A=diag⁡(λ1,λ2)\mat{A} = \diag(\lambda_1, \lambda_2)). Orbits satisfy ∣y2∣=c ∣y1∣λ2/λ1\abs{y_2} = c\,\abs{y_1}^{\lambda_2/\lambda_1}. With λ1,λ2\lambda_1, \lambda_2 of the same sign they are parabolic curves tangent at the origin to the slower-eigenvalue axis, with smaller ∣λ∣\abs{\lambda} (each half-axis is itself an orbit). Opposite signs make the ratio negative, producing hyperbolas with axes as asymptotes: only stable-axis orbits reach the origin.
  • Focus and center (C=αI+βJ\mat{C} = \alpha\mat{I} + \beta\mat{J}). In polar coordinates r′=αrr' = \alpha r and θ′=β\theta' = \beta, hence r=r0e(α/β)(θ−θ0)r = r_0 e^{(\alpha/\beta)(\theta - \theta_0)}: logarithmic spirals. At α=0\alpha = 0, rr is constant: circles, ellipses in the original basis, level curves of a conserved quadratic form V(x)=x⊤SxV(\vb{x}) = \vb{x}\T\mat{S}\vb{x} (with positive definite S\mat{S}).
  • Degenerate (Jλ\mat{J}_\lambda). Orbits are y1=eλt(c1+c2t)y_1 = e^{\lambda t}(c_1 + c_2 t), y2=c2eλty_2 = c_2 e^{\lambda t}: all become tangent, approaching or departing, to the sole eigenline (axis y1y_1).

A practical planar stability criterion follows: the origin is asymptotically stable if and only if τ<0\tau < 0 and δ>0\delta > 0. For real roots product δ>0\delta > 0 gives the same sign and sum τ<0\tau < 0 makes them negative; for complex roots their real part is τ/2\tau/2 and δ=α2+β2>0\delta = \alpha^2 + \beta^2 > 0 is already guaranteed.

Liouville’s formula: trace measures volume

The flow figure suggested a nonobvious fact: F’s area is multiplied by et tr⁡Ae^{t\,\tr\mat{A}}, depending on A\mat{A} only through its trace. This is general.

Proof

By Schur form, some invertible Q\mat{Q} gives A=QTQ−1\mat{A} = \mat{Q}\mat{T}\mat{Q}\inv with upper triangular T\mat{T} and eigenvalues λ1,…,λn\lambda_1, \dots, \lambda_n (with multiplicities) on the diagonal. Property (3) gives etA=QetTQ−1e^{t\mat{A}} = \mat{Q}e^{t\mat{T}}\mat{Q}\inv, and determinant is invariant under similarity. Powers of an upper triangular matrix remain upper triangular with diagonal λik\lambda_i^k, as does the etTe^{t\mat{T}} series, with diagonal ∑k(tλi)k/k!=etλi\sum_k (t\lambda_i)^k/k! = e^{t\lambda_i}. A triangular determinant is the diagonal product:

det⁡etA=∏i=1netλi=et∑iλi=et tr⁡A,\det e^{t\mat{A}} = \prod_{i=1}^n e^{t\lambda_i} = e^{t\sum_i\lambda_i} = e^{t\,\tr\mat{A}},

because trace is the eigenvalue sum.

∎

Thus det⁡etA>0\det e^{t\mat{A}} > 0 for real A\mat{A}, so flow preserves orientation: the F never flips. Since etAe^{t\mat{A}} is linear, it multiplies area (volume in dimension nn) of any set by its absolute determinant: the Jacobian of change of variables x↦etAx\vb{x} \mapsto e^{t\mat{A}}\vb{x} from lesson 11. Geometrically:

vol⁡(etAS)=et tr⁡Avol⁡(S).\operatorname{vol}\big(e^{t\mat{A}}S\big) = e^{t\,\tr\mat{A}}\operatorname{vol}(S).

Trace of A\mat{A} is also divergence of field x↦Ax\vb{x} \mapsto \mat{A}\vb{x} because ∇⋅(Ax)=∑i∂i(Ax)i=∑iaii\nabla\cdot(\mat{A}\vb{x}) = \sum_i \partial_i(\mat{A}\vb{x})_i = \sum_i a_{ii}. This is the linear case of the general fact: field divergence is the flow’s volume-expansion rate. (Hamiltonian mechanics has zero divergence and preserves phase-space volume: Liouville’s theorem in mechanics.) If tr⁡A<0\tr\mat{A} < 0 flow contracts, if tr⁡A>0\tr\mat{A} > 0 expands, and if tr⁡A=0\tr\mat{A} = 0 preserves volume despite deformation (the figure’s rotation and shear look nothing alike yet both have zero trace). Centers in plane (τ,δ)(\tau, \delta) lie at τ=0\tau = 0 for a deeper reason: an inward or outward spiral contracts or expands area, while a closed orbit enclosing the same region requires area-preserving flow.

A curiosity: since det⁡eA=etr⁡A>0\det e^{\mat{A}} = e^{\tr\mat{A}} > 0 for real A\mat{A}, matrices such as diag⁡(−1,1)\diag(-1, 1) (a reflection, determinant −1-1) are not the exponential of any real matrix. The formula also has a variable-coefficient version det⁡Φ(t)=det⁡Φ(t0)exp⁡ ⁣∫t0ttr⁡A(s) ⁣ds\det\mat{\Phi}(t) = \det\mat{\Phi}(t_0)\exp\!\int_{t_0}^t\tr\mat{A}(s)\dd s, proved from Jacobi’s determinant-derivative formula in an exercise.

Systems with input: Duhamel’s formula

A real system is rarely alone: external signal u(t)u(t) pushes it (force, voltage, control action, network-layer input). The input model is

x′(t)=Ax(t)+Bu(t),x(0)=x0,\vb{x}'(t) = \mat{A}\vb{x}(t) + \mat{B}\vb{u}(t), \qquad \vb{x}(0) = \vb{x}_0,

with B∈Rn×m\mat{B} \in \R^{n\times m} and piecewise-continuous u\vb{u}. The solution is the previous lesson’s variation of constants in matrix form.

Proof

Seek x(t)=etAc(t)\vb{x}(t) = e^{t\mat{A}}\vb{c}(t) with c\vb{c} unknown. By product rule and (etA)′=AetA(e^{t\mat{A}})' = \mat{A}e^{t\mat{A}},

x′=AetAc+etAc′=Ax+etAc′.\vb{x}' = \mat{A}e^{t\mat{A}}\vb{c} + e^{t\mat{A}}\vb{c}' = \mat{A}\vb{x} + e^{t\mat{A}}\vb{c}'.

For x\vb{x} to solve the equation we need etAc′=Bue^{t\mat{A}}\vb{c}' = \mat{B}\vb{u}, i.e. c′(t)=e−tABu(t)\vb{c}'(t) = e^{-t\mat{A}}\mat{B}\vb{u}(t). Integrating from c(0)=x0\vb{c}(0) = \vb{x}_0 gives c(t)=x0+∫0te−sABu(s) ⁣ds\vb{c}(t) = \vb{x}_0 + \int_0^t e^{-s\mat{A}}\mat{B}\vb{u}(s)\dd s; multiplying by etAe^{t\mat{A}} (entering the integral and using etAe−sA=e(t−s)Ae^{t\mat{A}}e^{-s\mat{A}} = e^{(t-s)\mat{A}}) yields the formula. The problem has a unique solution (Picard–Lindelöf on each interval where u\vb{u} is continuous, since the right side is Lipschitz in x\vb{x}, joining solutions at jumps of u\vb{u}), so this is it.

∎

Read it as superposed impulses. At each instant ss, input supplies an instantaneous push Bu(s) ⁣ds\mat{B}\vb{u}(s)\dd s, which evolves freely for remaining time t−st - s transported by e(t−s)Ae^{(t-s)\mat{A}}. Current state is evolved initial state plus the sum of evolved pushes.

If only linear output y=Cx\vb{y} = \mat{C}\vb{x} is observed and x0=0\vb{x}_0 = \vb{0}, the formula says y=h∗u\vb{y} = \vb{h} * \vb{u} is convolution with impulse response

h(t)=CetAB.\vb{h}(t) = \mat{C}e^{t\mat{A}}\mat{B}.

This identity (a linear time-invariant system is convolution whose kernel comes from etAe^{t\mat{A}}) allows training an SSM as a long convolution and running it as a recurrence at inference.

Discretization: from equation to recurrence

A computer handles sequences, not continuous tt. Suppose input is held constant on each interval of length Δ\Delta (zero-order hold, ZOH), u(t)=uk\vb{u}(t) = \vb{u}_k for t∈[kΔ,(k+1)Δ)t \in [k\Delta, (k+1)\Delta). Duhamel from kΔk\Delta to (k+1)Δ(k+1)\Delta gives an exact formula, not an approximation:

xk+1=Aˉ xk+Bˉ uk,Aˉ=eΔA,Bˉ=∫0ΔesA ⁣ds  B=A−1(eΔA−I)B,\vb{x}_{k+1} = \bar{\mat{A}}\,\vb{x}_k + \bar{\mat{B}}\,\vb{u}_k, \qquad \bar{\mat{A}} = e^{\Delta\mat{A}}, \qquad \bar{\mat{B}} = \int_0^\Delta e^{s\mat{A}}\dd s\;\mat{B} = \mat{A}\inv\big(e^{\Delta\mat{A}} - \mat{I}\big)\mat{B},

where the final equality requires invertible A\mat{A} (calculate the integral with  ⁣d ⁣dsesA=AesA\frac{\dd}{\dd s}e^{s\mat{A}} = \mat{A}e^{s\mat{A}}). For example, for x′=−x+ux' = -x + u and Δ=0.1\Delta = 0.1, Aˉ=e−0.1≈0.9048\bar{A} = e^{-0.1} \approx 0.9048 and Bˉ=1−e−0.1≈0.09516\bar{B} = 1 - e^{-0.1} \approx 0.09516.

There are other discretizations. For scalar mode x′=λxx' = \lambda x:

Methodaˉ\bar{a}Stable for every Δ\Delta if Re⁡λ<0\operatorname{Re}\lambda < 0?
Explicit Euler1+Δλ1 + \Delta\lambdano: requires ∣1+Δλ∣<1\abs{1 + \Delta\lambda} < 1
Implicit Euler11−Δλ\dfrac{1}{1 - \Delta\lambda}yes
Bilinear (Tustin, trapezoidal rule)1+Δλ/21−Δλ/2\dfrac{1 + \Delta\lambda/2}{1 - \Delta\lambda/2}yes
Zero-order holdeΔλe^{\Delta\lambda}yes (and exact)

The discrete recurrence is stable when eigenvalues of Aˉ\bar{\mat{A}} have modulus below 1, not negative real part: the discrete criterion must not be confused with continuous stability. With ZOH, eigenvalues of Aˉ\bar{\mat{A}} are eΔλie^{\Delta\lambda_i}, modulus eΔRe⁡λie^{\Delta\operatorname{Re}\lambda_i}, mapping the left half-plane into the unit disk for every Δ>0\Delta > 0. Bilinear also maps it into the disk. Explicit Euler does not: for very negative real λ\lambda, ∣1+Δλ∣<1\abs{1 + \Delta\lambda} < 1 requires Δ<2/∣λ∣\Delta < 2/\abs{\lambda} (the next lesson turns this into gradient-descent step-size condition).

State space models: memory and selectivity

Observing yk=Cxky_k = \mat{C}\vb{x}_k from x0=0\vb{x}_0 = \vb{0} unrolls the recurrence into discrete convolution,

yk=∑m=0k−1Km uk−1−m,Km=CAˉmBˉ,y_k = \sum_{m=0}^{k-1} K_m\,u_{k-1-m}, \qquad K_m = \mat{C}\bar{\mat{A}}^m\bar{\mat{B}},

with the same kernel obtained by integrating continuous impulse response over each step: Km=∫mΔ(m+1)ΔCesAB ⁣ds≈Δ h((m+12)Δ)K_m = \int_{m\Delta}^{(m+1)\Delta}\mat{C}e^{s\mat{A}}\mat{B}\dd s \approx \Delta\,h((m+\tfrac12)\Delta). Structured SSMs parameterize A\mat{A} with structure making kernel calculation and convolution cheap (diagonal plus low-rank correction in S4; diagonal in S4D and Mamba), and learn Δ\Delta as another parameter. Original S4 used bilinear discretization; Mamba uses ZOH, and S4D supports both. With diagonal A\mat{A} modes are scalar, λi\lambda_i, and kernel is a sum of discrete exponentials aˉim\bar{a}_i^m.

How long does the system remember? Mode ii loses factor e−1e^{-1} every mm steps with eΔλim=e−1e^{\Delta\lambda_i m} = e^{-1}, i.e. m=1/(Δ∣λi∣)m = 1/(\Delta\abs{\lambda_i}) steps, or continuous time 1/∣λi∣1/\abs{\lambda_i}. With pole λ=−2\lambda = -2 and Δ=0.05\Delta = 0.05 this is 1010 steps; with Δ=1\Delta = 1 it is 0.50.5 and each token erases almost everything before it. Memory in steps is set by product Δ∣λ∣\Delta\abs{\lambda}: a pole near zero or small step gives long memory.

InteractiveDiscretizing a state space model
Impulse response: continuous versus discrete
t (tiempo continuo)
Discrete poles eΔλe^{\Delta\lambda} in the zz plane
|z| = 1
  • continuous response h(t)=CetABh(t) = C e^{tA} B
  • exact discrete (zero-order hold), Km/ΔK_m / \Delta
View
Poles
−0.30
−2.00
0.40
∣aˉ∣=e−Δa\abs{\bar a} = e^{-\Delta a} (slow pole)0.8869
Memory in steps 1/(Δa)1/(\Delta a)8.3
Memory in time 1/a1/a3.3
Steps in window [0,12][0, 12]30
In Kernel view, a system with two real poles (or a complex pair) is discretized by zero-order hold. Points are discrete kernel Km/ΔK_m/\Delta, gray curve continuous response h(t)h(t), and right are discrete poles eΔλe^{\Delta\lambda} against the unit circle. Lower Δ\Delta until points and curve coincide; increase it to see memory in steps shorten and discrete poles approach 00. Enable bilinear method (hollow circles), and with both poles fast and large Δ\Delta see discrete poles become negative and kernel alternate signs. Selectivity view has one pole and one key token among noise: with Δ\Delta equal for all tokens the system forgets the key, while small Δ\Delta on noise preserves it.

Selectivity view shows Mamba’s central mechanism. In an invariant SSM (S4), Δ\Delta, B\mat{B} and C\mat{C} do not depend on input and the whole system is convolution. In Mamba, Δt\Delta_t, Bt\mat{B}_t and Ct\mat{C}_t are functions of token xt\vb{x}_t (typically Δt=softplus⁡(Wxt+b)\Delta_t = \operatorname{softplus}(\mat{W}\vb{x}_t + b)), making recurrence ht=eΔtAht−1+Bˉtxt\vb{h}_t = e^{\Delta_t\mat{A}}\vb{h}_{t-1} + \bar{\mat{B}}_t\vb{x}_t time-varying. With diagonal, negative-real-part A\mat{A}:

  • If Δt\Delta_t is large, eΔtA≈0e^{\Delta_t\mat{A}} \approx \mat{0} and Bˉt\bar{\mat{B}}_t reaches its maximum −A−1B-\mat{A}\inv\mat{B}: state resets and only current token matters.
  • If Δt\Delta_t is small, eΔtA≈Ie^{\Delta_t\mat{A}} \approx \mat{I} and Bˉt≈0\bar{\mat{B}}_t \approx \mat{0}: state is preserved and token ignored.

The model learns to modulate Δt\Delta_t as a gate (like a GRU’s). The cost of selectivity is losing convolution: no single kernel remains, so recurrence is computed with an associative parallel scan. Those details belong to sequence architectures; here we need the mathematics of Δ\Delta. In its reference implementation Mamba retains eΔAe^{\Delta\mat{A}} for Aˉ\bar{\mat{A}} but simplifies Bˉ≈ΔB\bar{\mat{B}} \approx \Delta\mat{B} (first-order Euler value).

Implementation from scratch

The series defines eAe^{\mat{A}} but is not a good algorithm. Compare three approaches:

  1. Truncated series: sum ∑k<KAk/k!\sum_{k<K}\mat{A}^k/k!. Theoretically exact, it fails in practice for large ∥A∥\norm{\mat{A}}: terms grow to ∥A∥k/k!\norm{\mat{A}}^k/k! (maximum of order e∥A∥e^{\norm{\mat{A}}}) before decaying, and when the answer is much smaller than the maximum (e.g. e−30e^{-30}) it is lost to cancellation.
  2. Diagonalization: VeΛV−1\mat{V}e^{\mat{\Lambda}}\mat{V}\inv. It works only if A\mat{A} is diagonalizable, and if nearly defective V\mat{V} is ill-conditioned and error is multiplied by κ(V)\kappa(\mat{V}).
  3. Scaling and squaring. Property (1) gives eA=(eA/2s)2se^{\mat{A}} = \big(e^{\mat{A}/2^s}\big)^{2^s}. Scaling and squaring chooses ss so ∥A∥/2s≤12\norm{\mat{A}}/2^s \le \tfrac12, computes eA/2se^{\mat{A}/2^s} with a short Taylor series (for ∥B∥≤12\norm{\mat{B}} \le \tfrac12, terms through B16/16!\mat{B}^{16}/16! leave truncation error below 3⋅10−203\cdot 10^{-20}, far below rounding), and squares the result ss times. Libraries use this method with Padé approximants instead of Taylor.
[ ]The matrix exponential three waysBrowser
import numpy as np
from scipy.linalg import expm

def expm_serie(A, terminos=80):
    """Suma directa de la serie de Taylor."""
    n = A.shape[0]
    S, T = np.eye(n), np.eye(n)
    for k in range(1, terminos):
        T = T @ A / k            # T = A^k / k!
        S = S + T
    return S

def expm_diag(A):
    """V diag(e^w) V^-1: solo para A diagonalizable."""
    w, V = np.linalg.eig(A)
    E = V @ np.diag(np.exp(w)) @ np.linalg.inv(V)
    return E.real if np.isrealobj(A) else E

def expm_ss(A, grado=18):
    """Escalado y cuadrado: Taylor de A / 2^s y s cuadrados."""
    nrm = np.linalg.norm(A, 1)
    s = max(0, int(np.ceil(np.log2(nrm / 0.5)))) if nrm > 0.5 else 0
    B = A / 2**s
    S, T = np.eye(A.shape[0]), np.eye(A.shape[0])
    for k in range(1, grado + 1):
        T = T @ B / k
        S = S + T
    for _ in range(s):
        S = S @ S
    return S

rng = np.random.default_rng(1)
M = rng.normal(size=(6, 6)); M *= 50 / np.linalg.norm(M, 2)
casos = {
    "rotación (ω = 3)": np.array([[0.0, -3.0], [3.0, 0.0]]),
    "defectiva [[−2, 1], [0, −2]]": np.array([[-2.0, 1.0], [0.0, -2.0]]),
    "no normal, autovalores −30 y −25": np.array([[-30.0, 20.0], [0.0, -25.0]]),
    "aleatoria 6×6 con ‖A‖₂ = 50": M,
}
print(f"{'caso':34s} {'serie':>10s} {'diagonal':>10s} {'esc.-cuad.':>10s}")
for nombre, A in casos.items():
    ref = expm(A)
    err = lambda E: np.linalg.norm(E - ref) / np.linalg.norm(ref)
    print(f"{nombre:34s} {err(expm_serie(A)):10.1e} {err(expm_diag(A)):10.1e} {err(expm_ss(A)):10.1e}")

# la cancelación a la vista: e^{-30} sumando su serie
s, t = 0.0, 1.0
for k in range(1, 400):
    s, t = s + t, t * (-30) / k
print(f"\nserie de e^(-30): {s:.3e}   exacto: {np.exp(-30):.3e}   término máximo: {30**30 / 2.65e32:.1e}")

All three methods correctly handle rotation, which is normal and moderate. The defective case breaks diagonalization: eig returns nearly singular V\mat{V} and relative error 0.580.58, meaning no correct digits. With eigenvalues −30-30 and −25-25 the opposite occurs: diagonalization succeeds (two distinct eigenvalues) and direct series loses everything because terms reach 101210^{12} while the result is order 10−1110^{-11} and relative error 101010^{10}. Scaling and squaring succeeds on all four with errors between 10−1510^{-15} and 10−1410^{-14}.

A short cell checks two numerical consequences of Liouville’s formula and noncommutativity.

[ ]Liouville and noncommutativityBrowser
import numpy as np
from scipy.linalg import expm

rng = np.random.default_rng(3)
A = rng.normal(size=(5, 5))
print("det e^A =", np.linalg.det(expm(A)), "  e^tr(A) =", np.exp(np.trace(A)))

N = np.array([[0.0, 1.0], [0.0, 0.0]])        # N y su traspuesta no conmutan
print("N N^T - N^T N =\n", N @ N.T - N.T @ N)
print("e^N e^(N^T) =\n", expm(N) @ expm(N.T))
print("e^(N+N^T)   =\n", expm(N + N.T))

Determinant of eAe^{\mat{A}} agrees with etr⁡Ae^{\tr\mat{A}} up to rounding even for unstructured A\mat{A}. And eNeN⊤e^{\mat{N}}e^{\mat{N}\T} is [2111]\begin{bmatrix} 2 & 1 \\ 1 & 1 \end{bmatrix} versus [1.5431.1751.1751.543]\begin{bmatrix} 1.543 & 1.175 \\ 1.175 & 1.543 \end{bmatrix} for eN+N⊤e^{\mat{N}+\mat{N}\T}: they differ.

Now Duhamel. A forced damped oscillator y′′+0.4y′+4y=cos⁡1.5ty'' + 0.4y' + 4y = \cos 1.5t is solved three ways: Duhamel integral (trapezoidal quadrature and e(t−s)Ae^{(t-s)\mat{A}} from the prior cell), solve_ivp, and exact zero-order-hold recurrence.

[ ]Duhamel versus solve_ivpBrowser
import numpy as np
from scipy.linalg import expm
from scipy.integrate import solve_ivp

A = np.array([[0.0, 1.0], [-4.0, -0.4]])
B = np.array([0.0, 1.0])
x0 = np.array([1.0, 0.0])
u = lambda t: np.cos(1.5 * t)
T = 6.0

# 1) Duhamel: x(T) = e^{TA} x0 + ∫ e^{(T-s)A} B u(s) ds   (trapecios)
s = np.linspace(0.0, T, 2001)
integrando = np.array([expm((T - si) * A) @ B * u(si) for si in s])
trapecios = ((integrando[1:] + integrando[:-1]) / 2 * np.diff(s)[:, None]).sum(axis=0)
x_duhamel = expm(T * A) @ x0 + trapecios

# 2) integrador numérico de alta precisión
sol = solve_ivp(lambda t, x: A @ x + B * u(t), (0, T), x0, rtol=1e-11, atol=1e-13)
x_ivp = sol.y[:, -1]

# 3) ZOH exacto con entrada constante a trozos: la comparamos con una entrada también constante a trozos
dt = 0.05
Abar = expm(dt * A)
Bbar = np.linalg.solve(A, Abar - np.eye(2)) @ B
uk = u(np.arange(int(round(T / dt))) * dt)         # u se mantiene en cada intervalo
x, y = x0.copy(), x0.copy()
for k in range(len(uk)):
    x = Abar @ x + Bbar * uk[k]                       # la recurrencia exacta
    sol_k = solve_ivp(lambda t, z: A @ z + B * uk[k], (0, dt), y, rtol=1e-12, atol=1e-14)
    y = sol_k.y[:, -1]                                # integrar cada intervalo con u constante
print("Duhamel (trapecios) :", x_duhamel, " error", np.linalg.norm(x_duhamel - x_ivp))
print("solve_ivp           :", x_ivp)
print("recurrencia ZOH     :", x, "  frente a integrar con u constante a trozos:", np.linalg.norm(x - y))

First error is quadrature error (second order in step, order 10−610^{-6} with 2000 intervals). The third is rounding: with piecewise-constant uu the recurrence is exact, not approximate, and its difference from solve_ivp interval integration is the integrator tolerance size.

With libraries

scipy.linalg.expm uses scaling and squaring with Padé approximants whose degree and scaling depend on norm of A\mat{A} (Al-Mohy and Higham, 2009). Moler and Van Loan’s classic Nineteen dubious ways to compute the exponential of a matrix (1978, revised 2003) explains why other methods are less reliable. For discretization, scipy.signal.cont2discrete implements ZOH, bilinear and others; PyTorch provides torch.linalg.matrix_exp with automatic differentiation.

[ ]cont2discrete versus the exact formulaBrowser
import numpy as np
from scipy.linalg import expm
from scipy.signal import cont2discrete

# SSM diagonal con tres polos reales estables
lam = np.array([-0.5, -2.0, -8.0])
A, B = np.diag(lam), np.ones((3, 1))
C, D = np.array([[1.0, 1.0, 1.0]]) / 3, np.zeros((1, 1))
dt = 0.1

Ad, Bd, Cd, Dd, _ = cont2discrete((A, B, C, D), dt, method="zoh")
Ab = expm(dt * A)
Bb = np.linalg.solve(A, Ab - np.eye(3)) @ B
print("ZOH   |Ā − Ā_scipy| =", np.abs(Ad - Ab).max(), "  |B̄ − B̄_scipy| =", np.abs(Bd - Bb).max())
print("B̄ diagonal exacta:", Bb.ravel(), "  = (e^{Δλ} − 1)/λ:", (np.exp(dt * lam) - 1) / lam)

Ai, Bi, *_ = cont2discrete((A, B, C, D), dt, method="bilinear")
print("polos discretos ZOH      :", np.diag(Ab))
print("polos discretos bilineal :", np.diag(Ai))

# el núcleo K_m = C Ā^m B̄ y la salida como convolución
n = 60
K = np.array([(Cd @ np.linalg.matrix_power(Ad, m) @ Bd).item() for m in range(n)])
u = np.random.default_rng(0).normal(size=n)
y_conv = np.array([sum(K[m] * u[k - 1 - m] for m in range(k)) for k in range(n)])
x, y_rec = np.zeros((3, 1)), []
for k in range(n):
    y_rec.append((Cd @ x).item())
    x = Ad @ x + Bd * u[k]
print("convolución frente a recurrencia:", np.abs(y_conv - np.array(y_rec)).max())
print("memoria del modo lento: 1/(Δ|λ|) =", 1 / (dt * 0.5), "pasos")

Recurrence and convolution give the same output up to rounding, which S4 exploits: process a long sequence in one convolution and generate token by token using recurrence without changing the model. In PyTorch:

import torch

A = torch.tensor([[0.0, 1.0], [-4.0, -0.4]], requires_grad=True)
E = torch.linalg.matrix_exp(0.05 * A)      # diferenciable: pasa gradiente a A
E.trace().backward()                       # d tr(e^{ΔA}) / dA

Common mistakes

Exercises

NumericThe determinant of e^A
A matrix A∈R3×3\mat{A} \in \R^{3\times 3} has trace 33. Calculate det⁡(eA)\det\big(e^{\mat{A}}\big).
QuizClassify the origin
Classify the origin of x′=Ax\vb{x}' = \mat{A}\vb{x} for these four matrices in order: A1=[12−21]\mat{A}_1 = \begin{bmatrix} 1 & 2 \\ -2 & 1 \end{bmatrix}, A2=[−100−3]\mat{A}_2 = \begin{bmatrix} -1 & 0 \\ 0 & -3 \end{bmatrix}, A3=[01−40]\mat{A}_3 = \begin{bmatrix} 0 & 1 \\ -4 & 0 \end{bmatrix}, A4=[200−1]\mat{A}_4 = \begin{bmatrix} 2 & 0 \\ 0 & -1 \end{bmatrix}.
ProofDerivative of e^{tA} from the series
Prove: For A∈Rn×n\mat{A} \in \R^{n\times n},  ⁣d ⁣dtetA=AetA\dfrac{\dd}{\dd t}e^{t\mat{A}} = \mat{A}e^{t\mat{A}}, by termwise differentiation.
0
Fix T>0T > 0 and work on [−T,T][-T, T] with a submultiplicative norm. Let SN(t)=∑k=0NtkAk/k!S_N(t) = \sum_{k=0}^N t^k\mat{A}^k/k!.

Step 1 of 4. Which lesson 14 theorem permits termwise differentiation of the limit of SNS_N?

NumericExact discretization of a mode
Discretize system x′=−x+ux' = -x + u by zero-order hold with step Δ=0.1\Delta = 0.1. Calculate Bˉ\bar{B} in xk+1=Aˉxk+Bˉukx_{k+1} = \bar{A}x_k + \bar{B}u_k.
ProofLiouville from Jacobi’s formula
Prove: Let X(t)=etA\mat{X}(t) = e^{t\mat{A}}. Prove det⁡X(t)=et tr⁡A\det\mat{X}(t) = e^{t\,\tr\mat{A}} using Jacobi’s formula  ⁣d ⁣dtdet⁡X(t)=det⁡X(t) tr⁡(X(t)−1X′(t))\dfrac{\dd}{\dd t}\det\mat{X}(t) = \det\mat{X}(t)\,\tr\big(\mat{X}(t)\inv\mat{X}'(t)\big) for invertible differentiable X(t)\mat{X}(t).
0
Let w(t)=det⁡X(t)w(t) = \det\mat{X}(t). You know X(0)=I\mat{X}(0) = \mat{I} and X′(t)=AX(t)\mat{X}'(t) = \mat{A}\mat{X}(t).

Step 1 of 2. What equation does ww satisfy?

NumericDuhamel with exponential input
Solve x′=−2x+e−tx' = -2x + e^{-t} with x(0)=0x(0) = 0 using Duhamel and give x(1)x(1).
NumericWhen they do not commute
Let N=[0100]\mat{N} = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}. Calculate tr⁡(eN+N⊤)\tr\big(e^{\mat{N}+\mat{N}\T}\big).
QuizStability after discretization
Mode x′=λxx' = \lambda x with λ=−50\lambda = -50 is stable. Discretize with Δ=0.1\Delta = 0.1. Which methods give stable recurrence xk+1=aˉ xkx_{k+1} = \bar{a}\,x_k (∣aˉ∣<1\abs{\bar{a}} < 1)?

More than one answer may be correct.

NumericMemory of a discretized pole
A mode with pole λ=−2\lambda = -2 is discretized by ZOH at step Δ=0.05\Delta = 0.05. How many steps until response decreases by factor ee (to e−1e^{-1})?
CodeMatrix exponential by scaling and squaring
Implement expm_scaling_squaring(A) returning eAe^{\mat{A}} by scaling and squaring: choose minimum s≥0s \ge 0 with ∥A∥1/2s≤0.5\norm{\mat{A}}_1/2^s \le 0.5, sum the Taylor series of A/2s\mat{A}/2^s with 18 terms, and square the result ss times. Do not use scipy.linalg.expm or np.linalg.eig. It must work for matrices of any size, A = 0 and very large norm.
import numpy as np

def expm_scaling_squaring(A):
  """Exponencial de matriz por escalado y cuadrado (Taylor de grado 18)."""
  A = np.asarray(A, dtype=float)
  # tu código: s mínimo con ||A||_1 / 2**s <= 0.5, serie de B = A / 2**s, y s cuadrados
  return np.eye(A.shape[0])
Shift+Enter to run

Summary

Key idea
Linear system x′=Ax\vb{x}' = \mat{A}\vb{x} is solved by matrix exponential x(t)=etAx0\vb{x}(t) = e^{t\mat{A}}\vb{x}_0, and eigenvalues of A\mat{A} determine behavior: for 2×22\times 2 trace and determinant give the entire phase portrait, while trace also measures volume expansion.
  • Exponential eA=∑Ak/k!e^{\mat{A}} = \sum\mat{A}^k/k! always converges, satisfies  ⁣d ⁣dtetA=AetA\frac{\dd}{\dd t}e^{t\mat{A}} = \mat{A}e^{t\mat{A}} and uniquely solves the problem. Equality eA+B=eAeBe^{\mat{A}+\mat{B}} = e^{\mat{A}}e^{\mat{B}} holds only if A\mat{A} and B\mat{B} commute.
  • Jordan form computes it: PetΛP−1\mat{P}e^{t\mat{\Lambda}}\mat{P}\inv in the diagonalizable case, eαte^{\alpha t} by rotation for complex eigenvalues α±iβ\alpha \pm i\beta, and polynomial factor tkeλtt^k e^{\lambda t} for defective blocks. The origin is asymptotically stable iff all eigenvalues have Re⁡λ<0\operatorname{Re}\lambda < 0.
  • In the plane, portrait (saddle, node, focus, center and boundary cases) is read from (τ,δ)(\tau, \delta) and parabola τ2=4δ\tau^2 = 4\delta. Centers and parabola cases are fragile.
  • Liouville: det⁡etA=et tr⁡A\det e^{t\mat{A}} = e^{t\,\tr\mat{A}}. Trace is field divergence and measures volume expansion: zero trace preserves area.
  • With input, x(t)=etAx0+∫0te(t−s)ABu(s) ⁣ds\vb{x}(t) = e^{t\mat{A}}\vb{x}_0 + \int_0^t e^{(t-s)\mat{A}}\mat{B}\vb{u}(s)\dd s (Duhamel), and output is convolution with CetAB\mat{C}e^{t\mat{A}}\mat{B}. Zero-order hold gives exact recurrence Aˉ=eΔA\bar{\mat{A}} = e^{\Delta\mat{A}}, Bˉ=A−1(eΔA−I)B\bar{\mat{B}} = \mat{A}\inv(e^{\Delta\mat{A}} - \mat{I})\mat{B}.
  • A mode’s memory is 1/(Δ∣λ∣)1/(\Delta\abs{\lambda}) steps; making Δ\Delta input-dependent is Mamba’s selectivity mechanism. Continuous stability (Re⁡λ<0\operatorname{Re}\lambda < 0) differs from discrete (∣λˉ∣<1\abs{\bar\lambda} < 1).
  • Numerically use scaling and squaring (or Padé) via scipy.linalg.expm: direct series and nearly defective diagonalization are unreliable.