Module contents
Lesson 11 of 25Core 100 min

Diagonalization, matrix functions and linear dynamics

Diagonalization chooses a basis where a matrix acts coordinate by coordinate, enabling powers, exponentials and other matrix functions. Study discrete and continuous linear systems, spectral-radius stability and its limits for nonnormal matrices, and Jordan form for defective matrices. This underlies state-space models.

After this lesson you can

  • Diagonalize a matrix when possible and use A = VΛV⁻¹ to calculate Aᵏ and f(A).
  • Solve linear recurrences in closed form and predict their asymptotic behavior.
  • Determine stability of xₖ₊₁ = Axₖ and x' = Ax from eigenvalues.
  • Compute a matrix exponential and use it to discretize a continuous system exactly.
  • Recognize transient growth of nonnormal matrices and the role of Jordan form.

Before you start

Motivation: systems evolving step by step

Many systems you will build have a state evolving by repeatedly applying the same matrix. Such a model is a linear dynamical system: in discrete time,

xk+1=Axk+Buk,\vb{x}_{k+1} = \mat{A}\vb{x}_k + \mat{B}\vb{u}_k,

and in continuous time, x′(t)=Ax(t)+Bu(t)\vb{x}'(t) = \mat{A}\vb{x}(t) + \mat{B}\vb{u}(t), with state x∈Rn\vb{x} \in \R^n, transition matrix A∈Rn×n\mat{A} \in \R^{n\times n} and external input u\vb{u}, often zero (an autonomous system). They appear in many settings:

  • Linear recurrent networks and state-space models. An SSM layer stores state ht=Aht−1+Bxt\vb{h}_t = \mat{A}\vb{h}_{t-1} + \mat{B}\vb{x}_t and emits yt=Cht\vb{y}_t = \mat{C}\vb{h}_t. Unrolling gives ht=∑s≤tAt−sBxs\vb{h}_t = \sum_{s \le t} \mat{A}^{t-s}\mat{B}\vb{x}_s: what the model remembers of a token kk steps ago is multiplied by Ak\mat{A}^k. If Ak\mat{A}^k explodes, gradients explode; if it quickly vanishes, the model forgets (see exploding and vanishing gradients). State-space models such as S4 and Mamba start with a continuous system and discretize it using a matrix exponential, constructed here.
  • Momentum. The heavy-ball method on a quadratic is a linear system in pair (wk,wk−1)(\vb{w}_k, \vb{w}_{k-1}); its convergence rate is the magnitude of eigenvalues of a matrix 2×22\times 2 (see stability below and momentum).
  • Markov chains, populations and time series. A chain’s distribution advances as πk+1⊤=πk⊤P\boldsymbol{\pi}_{k+1}\T = \boldsymbol{\pi}_k\T\mat{P}; a VAR model’s stationarity depends on its matrix eigenvalues (VAR stability).
  • Physics and control. A damped oscillator, circuit, or robot linearized around equilibrium is x′=Ax\vb{x}' = \mat{A}\vb{x}.

The shared question: what is xk=Akx0\vb{x}_k = \mat{A}^k\vb{x}_0 for large kk without computing kk products? Does it tend to zero, escape, oscillate? In continuous time, what is x(t)\vb{x}(t)? One idea answers: find a basis in which A\mat{A} does not mix coordinates. There, applying A\mat{A} a thousand times raises nn numbers to the thousandth power; any matrix function (square root, logarithm, exponential) applies the scalar function to those nn numbers.

Diagonalization: the basis where the matrix does not mix

In the previous lesson an eigenvector is a direction A\mat{A} only scales: Av=λv\mat{A}\vb{v} = \lambda\vb{v}. Suppose you have nn eigenvectors v1,…,vn\vb{v}_1, \dots, \vb{v}_n with eigenvalues λ1,…,λn\lambda_1, \dots, \lambda_n and place them in columns of V\mat{V}. The nn equalities Avj=λjvj\mat{A}\vb{v}_j = \lambda_j\vb{v}_j are one matrix equality, column by column:

AV=A[v1⋯vn]=[λ1v1⋯λnvn]=VΛ,Λ=diag⁡(λ1,…,λn).\mat{A}\mat{V} = \mat{A}\begin{bmatrix} \vb{v}_1 & \cdots & \vb{v}_n \end{bmatrix} = \begin{bmatrix} \lambda_1\vb{v}_1 & \cdots & \lambda_n\vb{v}_n \end{bmatrix} = \mat{V}\mat{\Lambda}, \qquad \mat{\Lambda} = \diag(\lambda_1, \dots, \lambda_n).

If the eigenvectors are also linearly independent, V\mat{V} is invertible and we can solve for A\mat{A}.

Read the factorization right to left as three steps applied to vector x\vb{x}. First c=V−1x\vb{c} = \mat{V}^{-1}\vb{x} are coordinates of x\vb{x} in the eigenvector basis: x=c1v1+⋯+cnvn\vb{x} = c_1\vb{v}_1 + \cdots + c_n\vb{v}_n. Then Λ\mat{\Lambda} multiplies each coordinate by its eigenvalue, without mixing coordinates. Finally V\mat{V} reconstructs the vector in the standard basis. In change-of-basis language, Λ\mat{\Lambda} is the same map’s matrix in the eigenvector basis, and A\mat{A} and Λ\mat{\Lambda} are similar. Diagonalization chooses a basis where the map is as simple as possible: nn independent scalings.

This is the matrix in the first interactive. On the left are iterations xk=Akx0\vb{x}_k = \mat{A}^k\vb{x}_0 in the standard basis with the deformed eigenvector-coordinate grid; on the right are the same iterations in those coordinates.

InteractiveThe diagonalization lens
Why is repeatedly applying A\mat{A} trivial in the eigenvector basis? Press play. On the left the trajectory first approaches the origin, then bends and escapes along v1\vb{v}_1; on the right, in coordinates c=V−1x\vb{c} = \mat{V}^{-1}\vb{x}, each step multiplies c1c_1 by λ1=1.2\lambda_1 = 1.2 and c2c_2 by λ2=0.6\lambda_2 = 0.6 without mixing: the orange arrow grows and aqua one shrinks. Drag x0\vb{x}_0 onto a dashed line: the trajectory no longer bends. Make λ2\lambda_2 negative to see jumps across the line of v1\vb{v}_1.

When does it exist?

The definition says what diagonalization is, not when it exists. The construction provides the answer:

Equivalence of 1 and 2 is the calculation above read both ways; you will prove it step by step in the exercises. Item 3 uses multiplicities: eigenvectors of distinct eigenvalues are independent, so combining eigenspace bases gives an independent set of ∑λdim⁡null⁡(A−λI)\sum_\lambda \dim\nullsp(\mat{A} - \lambda\mat{I}) vectors. Geometric multiplicity never exceeds algebraic, and algebraic multiplicities sum to nn, so nn is reached exactly when they agree for each eigenvalue. With nn distinct eigenvalues all multiplicities are 1 automatically.

The canonical counterexample is shear S=[1101]\mat{S} = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}. Its only eigenvalue is double λ=1\lambda = 1, but S−I=[0100]\mat{S} - \mat{I} = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix} has a one-dimensional null space: only one eigenvector line, axis x1x_1, insufficient for a basis. Such matrices are defective; we return to them later.

Complex eigenvalues and real form

A rotation Rθ\mat{R}_\theta with 0<θ<π0 < \theta < \pi fixes no real line and has no real eigenvectors. It does have them over C2\C^2: eigenvalues e±iθe^{\pm i\theta} are distinct, so Rθ\mat{R}_\theta is diagonalizable over C\C. Everything below works equally with complex V\mat{V} and Λ\mat{\Lambda}.

If A\mat{A} is real and λ=a+bi\lambda = a + bi (with b≠0b \ne 0) is an eigenvalue with eigenvector v=p+iq\vb{v} = \vb{p} + i\vb{q}, conjugate λˉ\bar{\lambda} is also an eigenvalue with eigenvector vˉ\bar{\vb{v}} (see complex eigenvalues). Separating real and imaginary parts of A(p+iq)=(a+bi)(p+iq)\mat{A}(\vb{p} + i\vb{q}) = (a + bi)(\vb{p} + i\vb{q}) gives Ap=ap−bq\mat{A}\vb{p} = a\vb{p} - b\vb{q} and Aq=bp+aq\mat{A}\vb{q} = b\vb{p} + a\vb{q}. In real basis P=[q  p]\mat{P} = [\vb{q}\ \ \vb{p}],

A=P[a−bba]P−1=P(r Rθ)P−1,r=∣λ∣,  θ=arg⁡λ.\mat{A} = \mat{P}\begin{bmatrix} a & -b \\ b & a \end{bmatrix}\mat{P}^{-1} = \mat{P}\left( r\,\mat{R}_\theta \right)\mat{P}^{-1}, \qquad r = \abs{\lambda},\ \ \theta = \arg\lambda .

This is real canonical form: in a suitable basis a complex eigenvalue pair corresponds to rotation by θ\theta followed by scaling by rr. A real 2×22\times 2 matrix with complex eigenvalues rotates (in an oblique basis) and scales; that is its entire dynamics.

Powers: the dominant eigenvalue governs

Diagonalization turns matrix powers into powers of numbers. Interior factors cancel:

Ak=(VΛV−1)(VΛV−1)⋯(VΛV−1)=VΛkV−1,Λk=diag⁡(λ1k,…,λnk).\mat{A}^k = (\mat{V}\mat{\Lambda}\mat{V}^{-1})(\mat{V}\mat{\Lambda}\mat{V}^{-1})\cdots(\mat{V}\mat{\Lambda}\mat{V}^{-1}) = \mat{V}\mat{\Lambda}^k\mat{V}^{-1}, \qquad \mat{\Lambda}^k = \diag(\lambda_1^k, \dots, \lambda_n^k).

Applied to an initial state, with c=V−1x0\vb{c} = \mat{V}^{-1}\vb{x}_0:

xk=Akx0=c1λ1k v1+c2λ2k v2+⋯+cnλnk vn.\vb{x}_k = \mat{A}^k\vb{x}_0 = c_1\lambda_1^k\,\vb{v}_1 + c_2\lambda_2^k\,\vb{v}_2 + \cdots + c_n\lambda_n^k\,\vb{v}_n .

This formula compresses the whole lesson. The state is a sum of modes: each is a fixed direction vi\vb{v}_i with weight evolving as geometric progression ciλikc_i\lambda_i^k. Modes do not interact. In the example, (Ak)11=(2⋅1.2k+0.6k)/3(\mat{A}^k)_{11} = (2\cdot 1.2^k + 0.6^k)/3 without a single matrix multiplication.

Order eigenvalues by magnitude and suppose one is strictly dominant, ∣λ1∣>∣λ2∣≥⋯\abs{\lambda_1} > \abs{\lambda_2} \ge \cdots, and c1≠0c_1 \ne 0. Factoring gives

xk=λ1k(c1v1+∑i≥2ci(λiλ1)kvi).\vb{x}_k = \lambda_1^k\left( c_1\vb{v}_1 + \sum_{i \ge 2} c_i\left(\frac{\lambda_i}{\lambda_1}\right)^k\vb{v}_i \right).

Ratios ∣λi/λ1∣<1\abs{\lambda_i/\lambda_1} < 1 make the sum vanish: the direction of xk\vb{x}_k converges to that of v1\vb{v}_1, with error of order ∣λ2/λ1∣k\abs{\lambda_2/\lambda_1}^k, and size grows or decays as ∣λ1∣k\abs{\lambda_1}^k. This is the principle of power iteration and PageRank: repeated multiplication extracts the dominant eigenvector, faster with a larger spectral gap.

Fibonacci in closed form

Recurrence Fk+2=Fk+1+FkF_{k+2} = F_{k+1} + F_k, with F0=0F_0 = 0 and F1=1F_1 = 1, is a two-dimensional linear system if the last two terms are stored:

[Fk+2Fk+1]=[1110]⏟F[Fk+1Fk],[Fk+1Fk]=Fk[10].\begin{bmatrix} F_{k+2} \\ F_{k+1} \end{bmatrix} = \underbrace{\begin{bmatrix} 1 & 1 \\ 1 & 0 \end{bmatrix}}_{\mat{F}}\begin{bmatrix} F_{k+1} \\ F_k \end{bmatrix}, \qquad \begin{bmatrix} F_{k+1} \\ F_k \end{bmatrix} = \mat{F}^k\begin{bmatrix} 1 \\ 0 \end{bmatrix}.

The characteristic polynomial of F\mat{F} is λ2−λ−1\lambda^2 - \lambda - 1, with roots φ=(1+5)/2≈1.618\varphi = (1 + \sqrt{5})/2 \approx 1.618 (the golden ratio) and ψ=(1−5)/2≈−0.618\psi = (1 - \sqrt{5})/2 \approx -0.618. Since F−λI=[1−λ11−λ]\mat{F} - \lambda\mat{I} = \begin{bmatrix} 1 - \lambda & 1 \\ 1 & -\lambda \end{bmatrix} and λ2=λ+1\lambda^2 = \lambda + 1, vector (λ,1)(\lambda, 1) lies in its null space: eigenvectors are v1=(φ,1)\vb{v}_1 = (\varphi, 1) and v2=(ψ,1)\vb{v}_2 = (\psi, 1). Write the initial state in that basis: (1,0)=c1(φ,1)+c2(ψ,1)(1, 0) = c_1(\varphi, 1) + c_2(\psi, 1) requires c1+c2=0c_1 + c_2 = 0 and c1φ+c2ψ=1c_1\varphi + c_2\psi = 1, hence c1=−c2=1/(φ−ψ)=1/5c_1 = -c_2 = 1/(\varphi - \psi) = 1/\sqrt{5}. The second coordinate of xk=c1φkv1+c2ψkv2\vb{x}_k = c_1\varphi^k\vb{v}_1 + c_2\psi^k\vb{v}_2 is Binet’s formula:

Fk=φk−ψk5.F_k = \frac{\varphi^k - \psi^k}{\sqrt{5}} .

Two immediate consequences. Since ∣ψk/5∣<1/2\abs{\psi^k/\sqrt{5}} < 1/2 for every k≥0k \ge 0, FkF_k is the integer nearest φk/5\varphi^k/\sqrt{5}: the dominant mode suffices. Ratio Fk+1/FkF_{k+1}/F_k tends to φ\varphi with error proportional to (∣ψ∣/φ)k=φ−2k≈0.382k(\abs{\psi}/\varphi)^k = \varphi^{-2k} \approx 0.382^k: each step gains a factor 2.62.6 in accuracy.

InteractiveFibonacci and the golden ratio
Where does Binet's formula come from? Return to k=0k = 0 and play: the direction of xk=(Fk+1,Fk)\vb{x}_k = (F_{k+1}, F_k) alternates around and approaches the eigenvector line of φ\varphi (the sign of ψk\psi^k alternates). The table splits each FkF_k into two modes: orange grows as φk\varphi^k, aqua alternates and shrinks, always below 1/21/2. Below, ratio error falls in a straight line on a log scale at the predicted slope ∣ψ∣/φ\abs{\psi}/\varphi. Choose ‘Free’ and drag x0\vb{x}_0 nearly onto the line of ψ\psi: with c1≈0c_1 \approx 0 convergence takes much longer to begin.

The same method solves any linear recurrence of order dd, ak+d=αd−1ak+d−1+⋯+α0aka_{k+d} = \alpha_{d-1}a_{k+d-1} + \cdots + \alpha_0 a_k: stack the last dd terms in a vector to obtain a system with a companion matrix, whose characteristic polynomial is the recurrence’s. If roots r1,…,rdr_1, \dots, r_d are distinct, the matrix is diagonalizable and ak=∑iβirika_k = \sum_i \beta_i r_i^k. With repeated roots the companion matrix is not diagonalizable and terms k rkk\,r^k appear; Jordan form later explains why.

Discrete dynamics: the phase plane

With n=2n = 2 we can see all dynamics of xk+1=Axk\vb{x}_{k+1} = \mat{A}\vb{x}_k in the plane. The mode formula says everything depends on the two eigenvalues’ positions relative to unit circle ∣λ∣=1\abs{\lambda} = 1:

EigenvaluesNameTrajectory behavior
real, ∣λ1∣,∣λ2∣<1\abs{\lambda_1}, \abs{\lambda_2} < 1stable nodeapproach 0\vb{0}; eventually tangent to the line of the greatest-magnitude eigenvalue (slow mode)
real, one inside and one outsidesaddleescape except those starting exactly on the line of the eigenvalue with magnitude below 1
real, both outsidesourceall escape except 0\vb{0}
some λ<0\lambda < 0(any of the above)that component changes sign each step: jumps between sides
complex re±iθr e^{\pm i\theta}, r<1r < 1stable spiralrotate θ\theta per step (in basis P\mat{P}) and shrink by rr
complex, r>1r > 1unstable spiralrotate and grow
complex, r=1r = 1centertrace fixed ellipses, neither inward nor outward
InteractiveDiscrete phase plane
What decides whether xk+1=Axk\vb{x}_{k+1} = \mat{A}\vb{x}_k tends to zero, escapes or rotates? Drag eigenvalues in the side panel (in ‘Complex’ mode conjugate λˉ\bar{\lambda} follows) and click the plane to launch trajectories. Move λ1\lambda_1 outside the circle and the node becomes a saddle: only the aqua line survives. Move an eigenvalue to the negative axis and trajectories jump sides. In complex mode cross the unit circle and the spiral changes from inward to outward (rotation direction stays the same); on the circle points follow gray ellipses.

Spectral radius and stability

The table suggests that convergence to zero depends only on the largest-magnitude eigenvalue.

Proof

If ρ(A)≥1\rho(\mat{A}) \ge 1, an eigenvalue ∣λ∣≥1\abs{\lambda} \ge 1 has eigenvector v≠0\vb{v} \ne \vb{0}, and ∥Akv∥=∣λ∣k∥v∥≥∥v∥\norm{\mat{A}^k\vb{v}} = \abs{\lambda}^k\norm{\vb{v}} \ge \norm{\vb{v}} does not tend to zero.

Conversely suppose ρ(A)<1\rho(\mat{A}) < 1 and, for now, diagonalizable A=VΛV−1\mat{A} = \mat{V}\mat{\Lambda}\mat{V}^{-1}. Use the Euclidean norm and its induced matrix norm ∥M∥2=max⁡x≠0∥Mx∥2/∥x∥2\norm{\mat{M}}_2 = \max_{\vb{x} \ne \vb{0}} \norm{\mat{M}\vb{x}}_2/\norm{\vb{x}}_2, which is submultiplicative. Since ∥Λk∥2=max⁡i∣λi∣k=ρk\norm{\mat{\Lambda}^k}_2 = \max_i\abs{\lambda_i}^k = \rho^k,

∥Ak∥2=∥VΛkV−1∥2≤∥V∥2 ∥V−1∥2 ρ(A)k=κ(V) ρ(A)k⟶0.\norm{\mat{A}^k}_2 = \norm{\mat{V}\mat{\Lambda}^k\mat{V}^{-1}}_2 \le \norm{\mat{V}}_2\,\norm{\mat{V}^{-1}}_2\,\rho(\mat{A})^k = \kappa(\mat{V})\,\rho(\mat{A})^k \longrightarrow 0 .

The non-diagonalizable case follows from Jordan form later (and is the second proof exercise).

∎

The proof’s bound contains a factor to watch: the condition number κ(V)=∥V∥∥V−1∥\kappa(\mat{V}) = \norm{\mat{V}}\norm{\mat{V}^{-1}} of the eigenvector matrix. It guarantees ∥Ak∥\norm{\mat{A}^k} eventually decays as ρk\rho^k, but not that it decays immediately. There is also an exact asymptotic characterization, Gelfand’s formula: ρ(A)=lim⁡k→∞∥Ak∥1/k\rho(\mat{A}) = \lim_{k\to\infty}\norm{\mat{A}^k}^{1/k} for any matrix norm. Spectral radius describes the long-term rate, saying little about initial steps.

Stable, but with a surprise

Take A=Vdiag⁡(0.9,0.8)V−1\mat{A} = \mat{V}\diag(0.9, 0.8)\mat{V}^{-1} with nearly parallel eigenvectors v1=(1,0)\vb{v}_1 = (1, 0) and v2=(cos⁡θ,sin⁡θ)\vb{v}_2 = (\cos\theta, \sin\theta). Spectral radius 0.90.9 makes the system stable. But a vector like x0=(0,1)\vb{x}_0 = (0, 1), nearly perpendicular to both, requires huge nearly opposite coefficients in that basis: x0=c1v1+c2v2\vb{x}_0 = c_1\vb{v}_1 + c_2\vb{v}_2 with c2=1/sin⁡θc_2 = 1/\sin\theta and c1=−cos⁡θ/sin⁡θc_1 = -\cos\theta/\sin\theta. Initially they cancel; since they decay at different rates (0.9k0.9^k versus 0.8k0.8^k), cancellation stops and xk\vb{x}_k grows substantially before both die away. With θ=2°\theta = 2°, ∥Ak∥2\norm{\mat{A}^k}_2 reaches 7.77.7 at k=6k = 6 and only falls below 1 at k=32k = 32; with θ=0.5°\theta = 0.5°, at 3131.

InteractiveStable, but with a surprise
If ρ(A)<1\rho(\mat{A}) < 1, can ∥Akx∥\norm{\mat{A}^k\vb{x}} grow before decaying? The magenta curve is ∥Ak∥2\norm{\mat{A}^k}_2, worst possible amplification in kk steps; blue is for your x0\vb{x}_0. Close angle θ\theta: the peak rises like κ(V)\kappa(\mat{V}) even though ρ=0.9\rho = 0.9 is unchanged, and the curve stays between ρk\rho^k (the eventual rate) and bound κ(V)ρk\kappa(\mat{V})\rho^k. Press ‘Worst initial direction’ to select the x0\vb{x}_0 attaining the peak. Open θ\theta to 90°90° (orthogonal eigenvectors) and the surprise disappears.

This is transient growth in nonnormal matrices. A matrix is normal if AA∗=A∗A\mat{A}\mat{A}^* = \mat{A}^*\mat{A}; normal matrices are exactly those diagonalizable with orthonormal eigenvectors (real symmetric matrices are studied with the spectral theorem). For them κ(V)=1\kappa(\mat{V}) = 1 and ∥Ak∥2=ρ(A)k\norm{\mat{A}^k}_2 = \rho(\mat{A})^k exactly: no surprise. Otherwise spectral intuition and actual behavior may differ by orders of magnitude; Trefethen and Embree’s book in the sources measures this.

Matrix functions

If Ak=VΛkV−1\mat{A}^k = \mat{V}\mat{\Lambda}^k\mat{V}^{-1}, summing powers with coefficients gives, for any polynomial p(z)=∑jajzjp(z) = \sum_j a_j z^j,

p(A)=∑jajAj=V(∑jajΛj)V−1=V diag⁡(p(λ1),…,p(λn)) V−1.p(\mat{A}) = \sum_j a_j\mat{A}^j = \mat{V}\left(\sum_j a_j\mat{\Lambda}^j\right)\mat{V}^{-1} = \mat{V}\,\diag\big(p(\lambda_1), \dots, p(\lambda_n)\big)\,\mat{V}^{-1}.

A polynomial acts on a diagonalizable matrix by acting on each eigenvalue. Generalization is immediate.

Check that it is independent of the chosen V\mat{V} (eigenvectors can be scaled, and any basis chosen inside an eigenspace of dimension above 1). Interpolation is the trick: if μ1,…,μm\mu_1, \dots, \mu_m are the distinct eigenvalues, there is a polynomial pp (Lagrange’s, of degree less than mm) with p(μj)=f(μj)p(\mu_j) = f(\mu_j). Then f(Λ)=p(Λ)f(\mat{\Lambda}) = p(\mat{\Lambda}) and f(A)=Vp(Λ)V−1=p(A)f(\mat{A}) = \mat{V}p(\mat{\Lambda})\mat{V}^{-1} = p(\mat{A}), depending only on A\mat{A}. Three useful properties follow: f(A)f(\mat{A}) commutes with A\mat{A} (it is a polynomial in A\mat{A}), every eigenvector vi\vb{v}_i of A\mat{A} is one of f(A)f(\mat{A}), and its eigenvalues are f(λi)f(\lambda_i). (There may be more eigenvectors: if ff takes the same value at two distinct eigenvalues, eigenspaces merge.) With ff equal to characteristic polynomial pAp_{\mat{A}}, zero at all eigenvalues, obtain pA(A)=0p_{\mat{A}}(\mat{A}) = \mat{0}: Cayley–Hamilton for diagonalizable matrices (it holds for all).

Square root. For the example matrix A=Vdiag⁡(1.2,0.6)V−1≈[0.98850.21390.10690.8815]\sqrt{\mat{A}} = \mat{V}\diag(\sqrt{1.2}, \sqrt{0.6})\mat{V}^{-1} \approx \begin{bmatrix} 0.9885 & 0.2139 \\ 0.1069 & 0.8815 \end{bmatrix}, squaring gives A\mat{A}. If A\sqrt{\mat{A}} advances the system “half a step”, At=VΛtV−1\mat{A}^t = \mat{V}\mat{\Lambda}^t\mat{V}^{-1} (with positive eigenvalues) interpolates the discrete trajectory at noninteger times. With nn distinct nonzero eigenvalues there are exactly 2n2^n square roots, one per sign choice; the principal root takes the root with positive real part for each eigenvalue and exists uniquely if no eigenvalue lies in (−∞,0](-\infty, 0]. Positive definite matrices have a symmetric principal square root used throughout. Beware repeated eigenvalues: identity I2\mat{I}_2 has infinitely many square roots, because any reflection H\mat{H} satisfies H2=I\mat{H}^2 = \mat{I}, and only ±I\pm\mat{I} are polynomials in I\mat{I} (the rest cannot be obtained with formula Vf(Λ)V−1\mat{V}f(\mat{\Lambda})\mat{V}^{-1}).

Logarithm. log⁡A=Vdiag⁡(log⁡λi)V−1\log\mat{A} = \mat{V}\diag(\log\lambda_i)\mat{V}^{-1} requires nonzero eigenvalues, and for the real principal logarithm none in (−∞,0)(-\infty, 0). For a rotation, log⁡Rθ=θ[0−110]\log\mat{R}_\theta = \theta\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix} if ∣θ∣<π\abs{\theta} < \pi. The logarithm inverts the exponential below and answers a practical question: if a system is observed every Δt\Delta t seconds and A\mat{A} estimated, which continuous system generated it? The answer is log⁡(A)/Δt\log(\mat{A})/\Delta t, with an ambiguity seen shortly.

The matrix exponential

The most important matrix function is defined without diagonalization by the same power series as the scalar exponential.

The series converges for every A\mat{A}: with a submultiplicative norm ∥Ak/k!∥≤∥A∥k/k!\norm{\mat{A}^k/k!} \le \norm{\mat{A}}^k/k!, and ∑k∥A∥k/k!=e∥A∥\sum_k \norm{\mat{A}}^k/k! = e^{\norm{\mat{A}}} is finite, so convergence is absolute (and uniform on ∥A∥≤R\norm{\mat{A}} \le R). If A=VΛV−1\mat{A} = \mat{V}\mat{\Lambda}\mat{V}^{-1}, summing term by term recovers the general definition: eA=Vdiag⁡(eλ1,…,eλn)V−1e^{\mat{A}} = \mat{V}\diag(e^{\lambda_1}, \dots, e^{\lambda_n})\mat{V}^{-1}.

Proof

(1) Both series converge absolutely, so their product can be rearranged (Cauchy product): eAeB=∑m∑j+k=mAjBkj! k!=∑m1m!∑j=0m(mj)AjBm−je^{\mat{A}}e^{\mat{B}} = \sum_{m}\sum_{j+k=m}\frac{\mat{A}^j\mat{B}^k}{j!\,k!} = \sum_m \frac{1}{m!}\sum_{j=0}^{m}\binom{m}{j}\mat{A}^j\mat{B}^{m-j}. If A\mat{A} and B\mat{B} commute, the binomial theorem applies to matrices and the inner sum is (A+B)m(\mat{A}+\mat{B})^m. Without commutation, (A+B)2=A2+AB+BA+B2≠A2+2AB+B2(\mat{A}+\mat{B})^2 = \mat{A}^2 + \mat{A}\mat{B} + \mat{B}\mat{A} + \mat{B}^2 \ne \mat{A}^2 + 2\mat{A}\mat{B} + \mat{B}^2 and the argument fails.

(2) sAs\mat{A} and tAt\mat{A} commute; apply (1). With s=−ts = -t obtain etAe−tA=e0=Ie^{t\mat{A}}e^{-t\mat{A}} = e^{\mat{0}} = \mat{I}.

(3) Series ∑ktkAk/k!\sum_k t^k\mat{A}^k/k! is a power series in tt with infinite convergence radius, differentiated term by term: ∑k≥1tk−1Ak/(k−1)!=AetA\sum_{k\ge1} t^{k-1}\mat{A}^k/(k-1)! = \mat{A}e^{t\mat{A}}, and factor A\mat{A} may come out on either side.

(4) (SAS−1)k=SAkS−1(\mat{S}\mat{A}\mat{S}^{-1})^k = \mat{S}\mat{A}^k\mat{S}^{-1} term by term.

(5) If A\mat{A} is diagonalizable, det⁡eA=∏ieλi=e∑iλi=etr⁡A\det e^{\mat{A}} = \prod_i e^{\lambda_i} = e^{\sum_i\lambda_i} = e^{\tr\mat{A}} (trace is the sum of eigenvalues, as seen). Diagonalizable matrices are dense (arbitrarily small perturbations separate eigenvalues) and both sides are continuous in A\mat{A}, so the identity holds for every matrix.

∎

The assumption in (1) matters. With A=[0100]\mat{A} = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix} and B=[0010]\mat{B} = \begin{bmatrix} 0 & 0 \\ 1 & 0 \end{bmatrix}, both nilpotent (A2=B2=0\mat{A}^2 = \mat{B}^2 = \mat{0}), the series terminate and eA=I+Ae^{\mat{A}} = \mat{I} + \mat{A}, eB=I+Be^{\mat{B}} = \mat{I} + \mat{B}:

eAeB=[2111],eA+B=[cosh⁡1sinh⁡1sinh⁡1cosh⁡1]≈[1.5431.1751.1751.543].e^{\mat{A}}e^{\mat{B}} = \begin{bmatrix} 2 & 1 \\ 1 & 1 \end{bmatrix}, \qquad 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}.

The discrepancy is measured by commutator [A,B]=AB−BA[\mat{A}, \mat{B}] = \mat{A}\mat{B} - \mat{B}\mat{A}: Baker–Campbell–Hausdorff gives etAetB=et(A+B)+t22[A,B]+O(t3)e^{t\mat{A}}e^{t\mat{B}} = e^{t(\mat{A}+\mat{B}) + \frac{t^2}{2}[\mat{A},\mat{B}] + \bigO(t^3)}. Splitting methods, taking one step with A\mat{A} and another with B\mat{B}, therefore incur error of order t2t^2 per step.

Solving x′=Ax\vb{x}' = \mat{A}\vb{x}

Property 3 says x(t)=etAx0\vb{x}(t) = e^{t\mat{A}}\vb{x}_0 satisfies x′=Ax\vb{x}' = \mat{A}\vb{x} and x(0)=x0\vb{x}(0) = \vb{x}_0. It is unique: if y\vb{y} is another,  ⁣d ⁣dt(e−tAy(t))=e−tA(y′−Ay)=0\frac{\dd}{\dd t}\big(e^{-t\mat{A}}\vb{y}(t)\big) = e^{-t\mat{A}}\big(\vb{y}' - \mat{A}\vb{y}\big) = \vb{0}, so e−tAy(t)e^{-t\mat{A}}\vb{y}(t) is constant and equal to x0\vb{x}_0. (This is the simplest case of linear ODE systems.) If A\mat{A} is diagonalizable, the solution is again a sum of modes:

x(t)=c1eλ1tv1+⋯+cneλntvn,∣eλt∣=eRe⁡(λ) t.\vb{x}(t) = c_1e^{\lambda_1 t}\vb{v}_1 + \cdots + c_ne^{\lambda_n t}\vb{v}_n, \qquad \abs{e^{\lambda t}} = e^{\operatorname{Re}(\lambda)\,t}.

Each mode’s size depends only on the eigenvalue’s real part; the imaginary part causes rotation. The stability boundary changes from the unit circle to the imaginary axis: etA→0e^{t\mat{A}} \to \mat{0} if and only if Re⁡λ<0\operatorname{Re}\lambda < 0 for every eigenvalue.

Exact discretization

Observing the continuous system every Δt\Delta t, property 2 gives a discrete system without error:

xk+1=x((k+1)Δt)=eΔtA x(kΔt)=Aˉxk,Aˉ=eΔtA.\vb{x}_{k+1} = \vb{x}\big((k+1)\Delta t\big) = e^{\Delta t\mat{A}}\,\vb{x}(k\Delta t) = \bar{\mat{A}}\vb{x}_k, \qquad \bar{\mat{A}} = e^{\Delta t\mat{A}}.

Eigenvalues of Aˉ\bar{\mat{A}} are μ=eΔtλ\mu = e^{\Delta t\lambda}, with ∣μ∣=eΔtRe⁡λ\abs{\mu} = e^{\Delta t\operatorname{Re}\lambda}. The exponential maps left half-plane Re⁡λ<0\operatorname{Re}\lambda < 0 inside the unit disk and the imaginary axis to its boundary: exact discretization preserves stability for any step size. Explicit Euler truncates the series after its first term, xk+1=(I+ΔtA)xk\vb{x}_{k+1} = (\mat{I} + \Delta t\mat{A})\vb{x}_k, with eigenvalues 1+Δtλ1 + \Delta t\lambda; it is stable only if ∣1+Δtλ∣<1\abs{1 + \Delta t\lambda} < 1, a disk centered at −1/Δt-1/\Delta t with radius 1/Δt1/\Delta t in plane λ\lambda. For a frictionless oscillator λ=±iω\lambda = \pm i\omega and ∣1+iωΔt∣=1+ω2Δt2>1\abs{1 + i\omega\Delta t} = \sqrt{1 + \omega^2\Delta t^2} > 1 for every step: Euler always injects energy.

InteractiveContinuous flow and exact discretization
What decides stability of x′=Ax\vb{x}' = \mat{A}\vb{x}, and how can it be discretized without breaking it? The system is oscillator x′′=(λ1+λ2)x′−λ1λ2 xx'' = (\lambda_1 + \lambda_2)x' - \lambda_1\lambda_2\,x in the (position, velocity) plane. Drag eigenvalues in the λ\lambda plane: the boundary is now the imaginary axis. Blue points (eΔtA)kx0(e^{\Delta t\mat{A}})^k\vb{x}_0 land exactly on the continuous curve for any Δt\Delta t; red Euler points escape when 1+Δtλ1 + \Delta t\lambda leaves the unit disk (with initial damping, at Δt>0.198\Delta t > 0.198). In the μ\mu plane the gray grid is the left half-plane's image under λ↦eΔtλ\lambda \mapsto e^{\Delta t\lambda}: vertical lines become circles, horizontal lines rays.

With input u\vb{u}, variation of constants also gives exact discretization when input is constant within each interval, called zero-order hold (ZOH):

 ⁣d ⁣dt(e−tAx(t))=e−tABu(t)\frac{\dd}{\dd t}\big(e^{-t\mat{A}}\vb{x}(t)\big) = e^{-t\mat{A}}\mat{B}\vb{u}(t)
Product rule and property 3 leave e−tA(x′−Ax)e^{-t\mat{A}}(\vb{x}' - \mat{A}\vb{x}), with x′=Ax+Bu\vb{x}' = \mat{A}\vb{x} + \mat{B}\vb{u}.
1/5

This is literally the discretization used in selective state-space models such as Mamba (Gu and Dao, 2023), applied with diagonal A\mat{A} so eΔtAe^{\Delta t\mat{A}} are nn scalar exponentials; S4 (Gu et al., 2021) used the bilinear transform, another discretization mapping the left half-plane to the disk. Again diagonalization makes computation cheap; see SSM discretization.

Defective matrices and Jordan form

The postponed case remains. The model non-diagonalizable matrix is the Jordan block

Jm(λ)=[λ1λ⋱⋱1λ]=λI+N,Nm=0,\mat{J}_m(\lambda) = \begin{bmatrix} \lambda & 1 & & \\ & \lambda & \ddots & \\ & & \ddots & 1 \\ & & & \lambda \end{bmatrix} = \lambda\mat{I} + \mat{N}, \qquad \mat{N}^m = \mat{0},

with one eigenvalue λ\lambda of algebraic multiplicity mm and one eigenvector e1\vb{e}_1. The central result says every matrix is built from these pieces.

We will not prove it (construction with generalized-eigenvector chains appears in advanced linear algebra texts). What you do need are its powers and exponential. Since λI\lambda\mat{I} and N\mat{N} commute, the binomial theorem applies and the series terminates at Nm−1\mat{N}^{m-1}:

Jk=∑j=0m−1(kj)λk−jNj,etJ=eλt∑j=0m−1tjj!Nj.\mat{J}^k = \sum_{j=0}^{m-1}\binom{k}{j}\lambda^{k-j}\mat{N}^j, \qquad e^{t\mat{J}} = e^{\lambda t}\sum_{j=0}^{m-1}\frac{t^j}{j!}\mat{N}^j .

For m=2m = 2:

Jk=[λkkλk−10λk],etJ=[eλtt eλt0eλt].\mat{J}^k = \begin{bmatrix} \lambda^k & k\lambda^{k-1} \\ 0 & \lambda^k \end{bmatrix}, \qquad e^{t\mat{J}} = \begin{bmatrix} e^{\lambda t} & t\,e^{\lambda t} \\ 0 & e^{\lambda t} \end{bmatrix}.

Polynomial factors kλk−1k\lambda^{k-1} and t eλtt\,e^{\lambda t} appear. The critically damped oscillator x′′+2x′+x=0x'' + 2x' + x = 0, with double eigenvalue −1-1, has solutions (a+bt)e−t(a + bt)e^{-t} for this reason, and recurrences with repeated roots have terms k rkk\,r^k. The stability theorem now holds for all matrices: each entry of Ak=PJkP−1\mat{A}^k = \mat{P}\mat{J}^k\mat{P}^{-1} combines terms (kj)λk−j\binom{k}{j}\lambda^{k-j} with j<mj < m, and if ∣λ∣<1\abs{\lambda} < 1, polynomial (kj)≤kj\binom{k}{j} \le k^j loses to geometric decay. At the boundary the distinction matters: with ∣λ∣=1\abs{\lambda} = 1 and a size-2 block, ∥Jk∥\norm{\mat{J}^k} grows as kk (marginal instability), while size-1 blocks remain bounded.

Why Jordan form is theoretical

Jordan form is discontinuous. Matrix Aε=[λ1ελ]\mat{A}_\varepsilon = \begin{bmatrix} \lambda & 1 \\ \varepsilon & \lambda \end{bmatrix} has eigenvalues λ±ε\lambda \pm \sqrt{\varepsilon}: for every ε>0\varepsilon > 0 they are distinct and Aε\mat{A}_\varepsilon is diagonalizable, whereas at ε=0\varepsilon = 0 it is a Jordan block. Three consequences become visible in the interactive:

  1. Eigenvalue sensitivity. A perturbation of size ε\varepsilon in one entry moves eigenvalues ε\sqrt{\varepsilon}: with ε=10−16\varepsilon = 10^{-16} (double-precision roundoff scale), 10−810^{-8}. For a block of size mm, the order is ε1/m\varepsilon^{1/m}.
  2. Nearly parallel eigenvectors. Eigenvectors are (1,±ε)(1, \pm\sqrt{\varepsilon}), and κ(V)\kappa(\mat{V}) grows as 1/ε1/\sqrt{\varepsilon}. Computing Ak\mat{A}^k or f(A)f(\mat{A}) as Vf(Λ)V−1\mat{V}f(\mat{\Lambda})\mat{V}^{-1} loses the corresponding digits.
  3. Powers do not reveal this. Aεk\mat{A}_\varepsilon^k is nearly identical to Jk\mat{J}^k: system behavior does not change, only its spectral description becomes fragile.
InteractiveNear Jordan form
What happens to diagonalization near a defective matrix? Decrease ε\varepsilon and follow the vertical line: eigenvalue separation (blue) is 2ε2\sqrt{\varepsilon}, much larger than perturbation (gray), and κ(V)\kappa(\mat{V}) (orange) grows like 1/ε1/\sqrt{\varepsilon}. Error in computing A20\mat{A}^{20} by diagonalization (magenta) rises toward u/εu/\sqrt{\varepsilon}, with u≈1.1⋅10−16u \approx 1.1\cdot 10^{-16}. Below, entry (1,2)(1, 2) of Aεk\mat{A}_\varepsilon^k, equal to ((λ+ε)k−(λ−ε)k)/(2ε)\big((\lambda + \sqrt{\varepsilon})^k - (\lambda - \sqrt{\varepsilon})^k\big)/(2\sqrt{\varepsilon}), nearly matches the Jordan block's kλk−1k\lambda^{k-1}: enable ε=0\varepsilon = 0 for an exact match, though V\mat{V} no longer exists. Raise ε\varepsilon to 10−110^{-1} to see the approximation holds only while kεk\sqrt{\varepsilon} is small.

Since rounding turns nearly any defective matrix into a diagonalizable one with ill-conditioned V\mat{V}, Jordan form is not computed in floating point: it is inherently unstable. Libraries use Schur decomposition, A=QTQ∗\mat{A} = \mat{Q}\mat{T}\mat{Q}^* with Q\mat{Q} unitary and T\mat{T} upper triangular, which exists for every matrix and is computed stably by unitary transformations (see eigenvalues on a computer). Jordan form supports reasoning (which terms appear, why factors tjeλtt^j e^{\lambda t} arise), not computation.

Implementation from scratch

First, diagonalization and powers. np.linalg.eig returns eigenvalues and V\mat{V} with unit eigenvectors in columns; V * lam**k multiplies column jj by λjk\lambda_j^k, giving VΛk\mat{V}\mat{\Lambda}^k without constructing the diagonal.

[ ]Powers by diagonalization and squaringBrowser
import numpy as np

def diagonalizar(A):
    """Devuelve (lam, V, V^{-1}) con A = V diag(lam) V^{-1}."""
    lam, V = np.linalg.eig(A)
    return lam, V, np.linalg.inv(V)

def potencia_diag(A, k):
    lam, V, Vinv = diagonalizar(A)
    return (V * lam**k) @ Vinv          # V diag(lam^k) V^{-1}

def potencia_cuadrados(A, k):
    """A^k con O(log k) productos: exponenciación binaria."""
    R = np.eye(A.shape[0], dtype=A.dtype)
    B = A.copy()
    while k > 0:
        if k & 1:
            R = R @ B
        B = B @ B
        k >>= 1
    return R

A = np.array([[1.0, 0.4], [0.2, 0.8]])
lam, V, Vinv = diagonalizar(A)
print("autovalores:", lam.real)
print("A^10 diagonalizando:\n", potencia_diag(A, 10).real)
print("A^10 por cuadrados:\n", potencia_cuadrados(A, 10))
print("fórmula (2·1.2^10 + 0.6^10)/3 =", (2 * 1.2**10 + 0.6**10) / 3)

If eig detects complex eigenvalues it returns complex arithmetic throughout; here they are real, but use .real just in case, since the imaginary part of real Ak\mat{A}^k can only be rounding. Now Fibonacci: the floating-point closed form versus matrix powers with Python exact integers (dtype=object), which never round.

[ ]Fibonacci: Binet versus exact powersBrowser
phi, psi = (1 + 5**0.5) / 2, (1 - 5**0.5) / 2

def fib_exacto(n):
    a, b = 0, 1
    for _ in range(n):
        a, b = b, a + b
    return a

def fib_binet(n):
    return round(phi**n / 5**0.5)        # el modo de psi ya no hace falta

print("F_30 =", fib_exacto(30), "y con Binet", fib_binet(30))
primer_fallo = next(n for n in range(200) if fib_binet(n) != fib_exacto(n))
print("Binet en coma flotante falla por primera vez en n =", primer_fallo)
print("  exacto:", fib_exacto(primer_fallo), "  Binet:", fib_binet(primer_fallo))

F = np.array([[1, 1], [1, 0]], dtype=object)
print("F_100 con la matriz entera:", potencia_cuadrados(F, 100)[0, 1])

F71≈3.1⋅1014F_{71} \approx 3.1\cdot 10^{14} is still exactly representable in double precision (all integers up to 253≈9⋅10152^{53} \approx 9\cdot 10^{15} are); φ71\varphi^{71} fails because its relative error, multiplied by 3⋅10143\cdot 10^{14}, already exceeds 1/21/2. The third cell measures the danger of diagonalizing nearly defective matrices: Aε=[0.91ε0.9]\mat{A}_\varepsilon = \begin{bmatrix} 0.9 & 1 \\ \varepsilon & 0.9 \end{bmatrix}, with A20\mat{A}^{20} by squaring as reference.

[ ]Diagonalizing a nearly defective matrixBrowser
print(f"{'eps':>8} {'cond(V)':>10} {'error de V L^20 V^-1':>22}")
for eps in [1e-2, 1e-4, 1e-6, 1e-8, 1e-10, 1e-12, 1e-14]:
    A = np.array([[0.9, 1.0], [eps, 0.9]])
    lam, V, Vinv = diagonalizar(A)
    ref = potencia_cuadrados(A, 20)
    err = np.linalg.norm(potencia_diag(A, 20) - ref) / np.linalg.norm(ref)
    print(f"{eps:8.0e} {np.linalg.cond(V):10.1e} {err:22.1e}")

Conditioning of V\mat{V} rises as 1/ε1/\sqrt{\varepsilon} and error from 10−1610^{-16} to about 10−1010^{-10}: six digits lost although the matrix looks ordinary.

The exponential three ways

Truncated Taylor series uses the definition; diagonalization uses formula VeΛV−1\mat{V}e^{\mat{\Lambda}}\mat{V}^{-1}. Compare both with scipy.linalg.expm on Moler and Van Loan’s classic example A0=[−4924−6431]\mat{A}_0 = \begin{bmatrix} -49 & 24 \\ -64 & 31 \end{bmatrix}, with eigenvalues −1-1 and −17-17, multiplied by tt.

[ ]Direct Taylor versus diagonalizationBrowser
from scipy.linalg import expm

def expm_taylor(A, N=200):
    """Suma directa de la serie con N términos."""
    S = np.eye(len(A))
    T = np.eye(len(A))
    for k in range(1, N):
        T = T @ A / k
        S = S + T
    return S

def expm_diag(A):
    lam, V = np.linalg.eig(A)
    return ((V * np.exp(lam)) @ np.linalg.inv(V)).real

A0 = np.array([[-49.0, 24.0], [-64.0, 31.0]])
print(f"{'t':>3} {'Taylor':>10} {'diagonal':>10}   (error relativo frente a expm)")
for t in [1, 2, 3, 5]:
    ref = expm(t * A0)
    e1 = np.linalg.norm(expm_taylor(t * A0) - ref) / np.linalg.norm(ref)
    e2 = np.linalg.norm(expm_diag(t * A0) - ref) / np.linalg.norm(ref)
    print(f"{t:3d} {e1:10.1e} {e2:10.1e}")

Ae = np.array([[-1.0, 1.0], [1e-14, -1.0]])      # casi defectiva
ref = expm(Ae)
print("casi defectiva, error de la diagonal:", np.linalg.norm(expm_diag(Ae) - ref) / np.linalg.norm(ref))

Direct Taylor becomes a disaster from t=2t = 2. Each term is theoretically exact, but intermediates of ∑k(tA0)k/k!\sum_k (t\mat{A}_0)^k/k! become enormous (with t=3t = 3, eigenvalue −51-51 produces terms of size 5151/51!≈102151^{51}/51! \approx 10^{21}) and cancel to yield order 10−110^{-1}, so rounding in large terms destroys all digits. This is catastrophic cancellation. Diagonalization succeeds here because eigenvectors are reasonably separated but loses many digits for the nearly defective matrix.

The standard solution is scaling and squaring: by property 2, eA=(eA/2s)2se^{\mat{A}} = \big(e^{\mat{A}/2^s}\big)^{2^s}. Choose ss so ∥A/2s∥≤1/2\norm{\mat{A}/2^s} \le 1/2; the series then has no large terms, converges quickly and avoids cancellation, then square ss times. You will implement it in the code exercise. Libraries replace the Taylor polynomial with a rational Padé approximant and choose ss and degree using rigorous error bounds.

Finally, the continuous-flow interactive’s damped oscillator in its initial state: eigenvalues λ=−0.1±i\lambda = -0.1 \pm i, i.e. x′′=(λ1+λ2)x′−λ1λ2 x=−0.2 x′−1.01 xx'' = (\lambda_1 + \lambda_2)x' - \lambda_1\lambda_2\,x = -0.2\,x' - 1.01\,x, with step Δt=0.5\Delta t = 0.5:

[ ]Exact discretization versus EulerBrowser
import matplotlib.pyplot as plt

sigma, omega, dt, pasos = -0.1, 1.0, 0.5, 60     # autovalores sigma ± i·omega
A = np.array([[0.0, 1.0], [-(sigma**2 + omega**2), 2 * sigma]])   # x'' = 2σx' − |λ|²x
Ad = expm(dt * A)                 # exacta
Ae = np.eye(2) + dt * A           # Euler explícito
x0 = np.array([2.6, 0.0])

X_ex, X_eu = [x0], [x0]
for _ in range(pasos):
    X_ex.append(Ad @ X_ex[-1])
    X_eu.append(Ae @ X_eu[-1])
X_ex, X_eu = np.array(X_ex), np.array(X_eu)
t = dt * np.arange(pasos + 1)
verdad = np.array([expm(tk * A) @ x0 for tk in t])

print("error máximo de la discretización exacta:", np.abs(X_ex - verdad).max())
print("|autovalores| exacta:", np.abs(np.linalg.eigvals(Ad)), " Euler:", np.abs(np.linalg.eigvals(Ae)))

h = dt / 10                       # curva continua: e^{hA} repetida, exacta en cada muestra
E, curva = expm(h * A), [x0]
for _ in range(10 * pasos):
    curva.append(E @ curva[-1])
tt, curva = h * np.arange(10 * pasos + 1), np.array(curva)

fig, ax = plt.subplots(figsize=(7, 3.2))
ax.plot(tt, curva[:, 0], color="0.35", lw=1.5, label="solución exacta")
ax.plot(t, X_ex[:, 0], "o", ms=4, label="discretización exacta")
ax.plot(t, X_eu[:, 0], "o-", ms=3, lw=0.8, label="Euler explícito")
ax.set_ylim(-8, 8)
ax.set_xlabel("t")
ax.set_ylabel("posición $x_1$")
ax.legend(loc="upper left")
plt.show()

Exact discretization matches the solution up to rounding; Euler has eigenvalue magnitude 1.0741.074 and amplitude grows by just over 7%7\% per step even as the real system loses energy.

The professional version

SciPy implements all matrix functions in this lesson; know what each does internally:

FunctionCalculatesHow (and why it does not diagonalize)
scipy.linalg.expm(A)eAe^{\mat{A}}scaling and squaring with variable-degree Padé approximants (Al-Mohy and Higham, 2009)
scipy.sparse.linalg.expm_multiply(A, v)etAve^{t\mat{A}}\vb{v} without forming etAe^{t\mat{A}}matrix-vector products with truncated Taylor and scaling; ideal for large sparse A\mat{A}
scipy.linalg.sqrtm(A), logm(A)principal square root and logarithmSchur decomposition, stable even when A\mat{A} is nearly defective
scipy.linalg.funm(A, f)f(A)f(\mat{A}) for any scalar ffSchur and Parlett recurrence; loses accuracy with very close eigenvalues
np.linalg.matrix_power(A, k)Ak\mat{A}^kexponentiation by squaring, like potencia_cuadrados
torch.linalg.matrix_exp(A)batched eAe^{\mat{A}} on GPU, differentiablescaling and squaring; suitable inside a network
[ ]Matrix functions with SciPyBrowser
from scipy.linalg import sqrtm, logm, funm
from scipy.sparse.linalg import expm_multiply

A = np.array([[1.0, 0.4], [0.2, 0.8]])
R = sqrtm(A)
print("sqrt(A) =\n", R, "\n¿R @ R == A?", np.allclose(R @ R, A))
print("¿expm(logm(A)) == A?", np.allclose(expm(logm(A)), A))
print("¿funm(A, cos) == Re e^{iA}?", np.allclose(funm(A, np.cos), expm(1j * A).real))

# e^{A+B} frente a e^A e^B con matrices que no conmutan
N1 = np.array([[0.0, 1.0], [0.0, 0.0]])
N2 = N1.T
print("e^(A+B) =\n", expm(N1 + N2))
print("e^A e^B =\n", expm(N1) @ expm(N2))

# e^{tJ} v en 5 instantes entre 0 y pi, sin formar e^{tJ}
J = np.array([[0.0, -1.0], [1.0, 0.0]])
print(expm_multiply(J, np.array([1.0, 0.0]), start=0, stop=np.pi, num=5, endpoint=True).round(6))

The correspondence is direct: expm is your scaling and squaring with a better polynomial; sqrtm, logm and funm are Vf(Λ)V−1\mat{V}f(\mat{\Lambda})\mat{V}^{-1} with ill-conditioned V\mat{V} replaced by unitary Q\mat{Q} and a triangular matrix. In PyTorch, SSM discretization is torch.linalg.matrix_exp(dt * A) or, if A\mat{A} is diagonal (usual), torch.exp(dt * a) elementwise:

import torch

def discretizar_zoh(a, B, dt):
    """SSM diagonal: a (n,) autovalores continuos, B (n, d). Devuelve A_bar (n,) y B_bar (n, d)."""
    a_bar = torch.exp(dt * a)                      # e^{dt A} con A = diag(a)
    b_bar = ((a_bar - 1) / a)[:, None] * B         # A^{-1}(e^{dt A} - I) B, fila a fila
    return a_bar, b_bar

Common mistakes

Exercises

ProofDiagonalizable exactly when there is an eigenvector basis
Prove: A∈Cn×n\mat{A} \in \C^{n\times n} is diagonalizable if and only if there is a basis of Cn\C^n consisting of eigenvectors of A\mat{A}.
0
Write V=[v1⋯vn]\mat{V} = [\vb{v}_1 \cdots \vb{v}_n] and Λ=diag⁡(λ1,…,λn)\mat{\Lambda} = \diag(\lambda_1, \dots, \lambda_n).

Step 1 of 4. (⇒\Rightarrow) Suppose A=VΛV−1\mat{A} = \mat{V}\mat{\Lambda}\mat{V}^{-1}. Which equality should be read column by column?

ProofSpectral radius below 1 implies vanishing powers
Prove: If ρ(A)<1\rho(\mat{A}) < 1, then Ak→0\mat{A}^k \to \mat{0}. First for diagonalizable A\mat{A}, then for all A\mat{A} using Jordan form.
0
Use the Euclidean-induced matrix norm, which is submultiplicative: ∥MN∥2≤∥M∥2∥N∥2\norm{\mat{M}\mat{N}}_2 \le \norm{\mat{M}}_2\norm{\mat{N}}_2.

Step 1 of 4. With A=VΛV−1\mat{A} = \mat{V}\mat{\Lambda}\mat{V}^{-1}, how do you write Ak\mat{A}^k?

NumericFibonacci by diagonalization
Using Binet's formula Fk=(φk−ψk)/5F_k = (\varphi^k - \psi^k)/\sqrt{5} and F0=0F_0 = 0, F1=1F_1 = 1, calculate F30F_{30}.
NumericA power without matrix multiplication
Given A=[10.40.20.8]=Vdiag⁡(1.2,0.6)V−1\mat{A} = \begin{bmatrix} 1 & 0.4 \\ 0.2 & 0.8 \end{bmatrix} = \mat{V}\diag(1.2, 0.6)\mat{V}^{-1} and V=[2−111]\mat{V} = \begin{bmatrix} 2 & -1 \\ 1 & 1 \end{bmatrix}, calculate entry (2,1)(2, 1) of A10\mat{A}^{10}.
NumericExponential of a rotation generator
For A=[0−110]\mat{A} = \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix} and t=π/2t = \pi/2, calculate entry (2,1)(2, 1) of etAe^{t\mat{A}}.
NumericDeterminant of an exponential
Calculate det⁡(eA)\det\big(e^{\mat{A}}\big) for A=[123−4]\mat{A} = \begin{bmatrix} 1 & 2 \\ 3 & -4 \end{bmatrix} without calculating eAe^{\mat{A}}.
NumericEuler's maximum step
The interactive oscillator has eigenvalues λ=−0.1±i\lambda = -0.1 \pm i. What is the largest Δt\Delta t for which explicit Euler, xk+1=(I+ΔtA)xk\vb{x}_{k+1} = (\mat{I} + \Delta t\mat{A})\vb{x}_k, is stable?
QuizExponential of a sum
Which condition guarantees eA+B=eAeBe^{\mat{A}+\mat{B}} = e^{\mat{A}}e^{\mat{B}}?
QuizWhat survives in a saddle
xk+1=Axk\vb{x}_{k+1} = \mat{A}\vb{x}_k has eigenvalues 0.50.5 (eigenvector v1\vb{v}_1) and −1.2-1.2 (eigenvector v2\vb{v}_2). For which x0\vb{x}_0 does xk→0\vb{x}_k \to \vb{0}?
QuizWhat the spectral radius guarantees
A real matrix A\mat{A} has ρ(A)=0.5\rho(\mat{A}) = 0.5. What can you guarantee?
QuizSquare roots of the identity
How many real 2×22\times 2 matrices X\mat{X} satisfy X2=I\mat{X}^2 = \mat{I}?
QuizTwo continuous systems, the same samples
With step size Δt=1\Delta t = 1, which continuous eigenvalue gives the same discrete eigenvalue eΔtλe^{\Delta t\lambda} as λ=−0.1+0.5i\lambda = -0.1 + 0.5i?
CodeThe exponential by scaling and squaring
Implement expm_scaling_squaring(A, m=16) without using scipy.linalg.expm: choose the smallest integer s≥0s \ge 0 with ∥A∥1/2s≤1/2\norm{\mat{A}}_1/2^s \le 1/2, sum the degree-mm Taylor polynomial of B=A/2s\mat{B} = \mat{A}/2^s, and square the result ss times. The tests compare with scipy.linalg.expm on large-norm matrices, including the Moler and Van Loan example with t=3t = 3, where the direct series gives a relative error of order 10610^{6}, and a nearly defective matrix.
import numpy as np

def expm_scaling_squaring(A, m=16):
  """Devuelve e^A por escalado y cuadrado con Taylor de grado m."""
  A = np.asarray(A, dtype=float)
  # 1. s: el menor entero >= 0 con norma1(A) / 2**s <= 1/2
  # 2. X = I + B + B^2/2! + ... + B^m/m!, con B = A / 2**s
  # 3. X = X @ X, s veces
  ...
Shift+Enter to run

Summary

  • Diagonalization chooses the eigenvector basis: A=VΛV−1\mat{A} = \mat{V}\mat{\Lambda}\mat{V}^{-1} exists if and only if there are nn independent eigenvectors, and in that basis A\mat{A} acts coordinate by coordinate.
  • Powers and functions pass to the eigenvalues: Ak=VΛkV−1\mat{A}^k = \mat{V}\mat{\Lambda}^k\mat{V}^{-1}, f(A)=Vf(Λ)V−1f(\mat{A}) = \mat{V}f(\mat{\Lambda})\mat{V}^{-1}. A linear system is a sum of modes ciλikvic_i\lambda_i^k\vb{v}_i (or cieλitvic_ie^{\lambda_i t}\vb{v}_i), and the dominant one wins in the long run.
  • Stability: in discrete time, ρ(A)<1\rho(\mat{A}) < 1; in continuous time, Re⁡λ<0\operatorname{Re}\lambda < 0. The exponential eΔtAe^{\Delta t\mat{A}} maps one boundary to the other and gives the exact discretization used by SSMs; Euler does not preserve it.
  • The spectral radius does not tell the whole story: with nearly parallel eigenvectors (large κ(V)\kappa(\mat{V})), a stable matrix amplifies enormously before decaying.
  • Jordan form explains the kλk−1k\lambda^{k-1} and t eλtt\,e^{\lambda t} factors of defective matrices, but is discontinuous: on a computer we use Schur and scaling and squaring, never an ill-conditioned V\mat{V}.
Key idea
In the eigenvector basis, a matrix is a list of numbers: its powers, exponential, and stability can be read from its eigenvalues. What that reading misses is the angle between eigenvectors, where transient growth and numerical instability arise.