---
title: Diagonalization and matrix powers
heading: What happens after many steps
eyebrow: A7 · Lesson 34 · Diagonalization
xp: 40
---

::: hook
A wireless link flips between a good state and a bad state, with fixed chances of switching each millisecond. In the long run, what fraction of the time is it bad, and how quickly does it forget where it started? A digital filter updates its internal state by the same matrix at every sample: will that state die away or blow up? Both questions ask what $A^k$ does for large $k$. Multiplying $A$ by itself a thousand times would answer it slowly. **Diagonalizing** $A$ answers it at once, through its eigenvalues.
:::

::: play
- A two-state link: each step, a good link goes bad with probability $a$, and a bad link recovers with probability $b$. The staircase is the probability of being good after $k$ steps, starting good.
- It settles at $\frac{b}{a + b}$. The gap shrinks by the factor $1 - a - b$ each step: that's the second eigenvalue of the transition matrix.
- Make $a + b$ close to 1. Make it small. Make it bigger than 1. How does the approach change?
:::
:::

```sim plot
view: graph
x: k = 0..30
y: P = 0..1
slider: a = 0.01..0.9 step 0.01 = 0.1
slider: b = 0.01..0.9 step 0.01 = 0.3
plot: b/(a + b) + (1 - b/(a + b))*(1 - a - b)^floor(k) | label: P(good) | samples: 800
plot: b/(a + b) | label: long-run share | color: ch3
readout: second eigenvalue = 1 - a - b | digits: 3
readout: long-run P(good) = b/(a + b) | digits: 4
```

::: predict
## $A$ has eigenvalues 2 and 0.5. After many steps, what does $A^k\mathbf{u}_0$ look like?

- [x] It grows like $2^k$, along the eigenvector for 2
- [ ] It shrinks like $0.5^k$
- [ ] It settles to a fixed vector
- [ ] It oscillates

::: reveal
It grows like $2^k$ and lines up with the eigenvector for 2. Write $\mathbf{u}_0$ as a combination of eigenvectors; each step multiplies each piece by its own eigenvalue. The piece with eigenvalue 0.5 dies away, and the piece with eigenvalue 2 doubles every step, so it soon dominates.
:::
:::

::: nameit
## Diagonalization

If an $n \times n$ matrix $A$ has $n$ independent eigenvectors, put them in the columns of $X$ and the eigenvalues on the diagonal of $\Lambda$. Then $AX = X\Lambda$, so

$$A = X\Lambda X^{-1} \qquad A^k = X\Lambda^kX^{-1}$$

and $\Lambda^k$ is easy: raise each eigenvalue to the $k$th power. Distinct eigenvalues guarantee independent eigenvectors. A matrix like $\begin{bmatrix}1 & 1\\0 & 1\end{bmatrix}$, with a repeated eigenvalue and only one eigenvector direction, can't be diagonalized.

## Difference equations

For $\mathbf{u}_{k+1} = A\mathbf{u}_k$, write $\mathbf{u}_0 = c_1\mathbf{x}_1 + \cdots + c_n\mathbf{x}_n$ in eigenvectors. Then

$$\mathbf{u}_k = c_1\lambda_1^k\mathbf{x}_1 + \cdots + c_n\lambda_n^k\mathbf{x}_n$$

- All $|\lambda_i| < 1$: $\mathbf{u}_k \to \mathbf{0}$. A digital filter whose state matrix has this property is **stable**.
- Some $|\lambda| > 1$: the state grows without limit.
- The largest $|\lambda|$ sets the long-run growth; the second largest sets how fast the others fade.

## Markov matrices

A **Markov matrix** has nonnegative entries and columns adding to 1: column $j$ lists the probabilities of moving from state $j$ to each state. It always has the eigenvalue 1, whose eigenvector (scaled to add to 1) is the **steady state**. For the two-state link,

$$A = \begin{bmatrix}1 - a & b\\a & 1 - b\end{bmatrix} \qquad \lambda = 1,\; 1 - a - b \qquad \text{steady state } \left(\tfrac{b}{a + b}, \tfrac{a}{a + b}\right)$$
:::

::: example
## Diagonalize $A = \begin{bmatrix}4 & 1\\2 & 3\end{bmatrix}$ and find $A^3(1, 0)$.

::: solution
1. **Eigenvalues.** The trace is 7 and the determinant 10, so
   $$\lambda^2 - 7\lambda + 10 = 0$$
   giving $\lambda = 5$ and $2$.
2. **Eigenvectors.** $(1, 1)$ for 5 and $(1, -2)$ for 2.
3. **Split the start.**
   $$(1, 0) = \tfrac{2}{3}(1, 1) + \tfrac{1}{3}(1, -2)$$
4. **Apply $A^3$.** Each piece is multiplied by its eigenvalue cubed:
   $$\begin{aligned} A^3(1, 0) &= \tfrac{2}{3}\cdot 125\,(1, 1) \\ &\quad + \tfrac{1}{3}\cdot 8\,(1, -2) \\ &= (86, 78) \end{aligned}$$
5. **Check by multiplying directly.**
   $$\begin{aligned} (1, 0) &\to (4, 2) \\ &\to (18, 14) \\ &\to (86, 78) \end{aligned}$$

**Answer:** $A$ has eigenvalues 5 and 2 with eigenvectors $(1, 1)$ and $(1, -2)$, and $A^3(1, 0) = (86, 78)$.
:::
:::

::: example
## Estimate the 20th Fibonacci number from eigenvalues.

::: solution
1. **Write the recurrence as a matrix.** $F_{k+2} = F_{k+1} + F_k$ is
   $$\mathbf{u}_{k+1} = \begin{bmatrix}1 & 1\\1 & 0\end{bmatrix}\mathbf{u}_k$$
2. **Eigenvalues.**
   $$\begin{aligned} \varphi &= \frac{1 + \sqrt 5}{2} \\ &= 1.618 \\ \lambda_2 &= \frac{1 - \sqrt 5}{2} \\ &= -0.618 \end{aligned}$$
3. **Keep the large one.** The second dies away, leaving
   $$F_k \approx \frac{\varphi^k}{\sqrt 5}$$
4. **Evaluate at $k = 20$.**
   $$\frac{1.618034^{20}}{\sqrt 5} = 6765.00$$
   and $F_{20} = 6765$.

**Answer:** the estimate gives 6765.00, and $F_{20} = 6765$.
:::
:::

::: example
## Each second a channel stays good with probability 0.9 and recovers from bad with probability 0.2: $M = \begin{bmatrix}0.9 & 0.2\\0.1 & 0.8\end{bmatrix}$. What fraction of the time is it good, in the long run?

::: solution
1. **Steady state.** The columns sum to 1, so 1 is an eigenvalue. Its eigenvector solves
   $$0.1x = 0.2y$$
   so it's proportional to $(2, 1)$; scaled to sum to 1, it's $(0.667, 0.333)$.
2. **Read it.** The channel is good two thirds of the time.
3. **The other eigenvalue.** It's the trace minus 1, 0.7. Any starting split approaches the steady state with the difference shrinking by 0.7 each second.
4. **After 10 seconds.** The difference is down to
   $$0.7^{10} = 2.8\%$$
   of where it started.

**Answer:** in the long run the channel is good two thirds of the time.
:::
:::

::: check
given: a = 3 | 4 | 6; let am1 = a - 1
answer: a + 1

## What is the larger eigenvalue of $\begin{bmatrix}\given{a} & 1\\2 & \given{am1}\end{bmatrix}$?

::: right
Right. The trace is $2a - 1$ and the determinant $a^2 - a - 2 = (a - 2)(a + 1)$, so the eigenvalues are $a + 1$ = {answer} and $a - 2$.
:::

::: misses
- [a - 2] That's the smaller one.
- [a] The diagonal entries are the eigenvalues only for a triangular matrix.
- [any] Not yet. Use the trace and determinant: $\lambda^2 - (\text{trace})\lambda + \det = 0$.
:::
:::

::: check
given: a = 0.1 | 0.05 | 0.2; b = 0.3 | 0.4
answer: b/(a + b)
tolerance: 0.5%

## A link goes bad with probability {a} per step and recovers with probability {b}. In the long run, what fraction of the time is it good?

::: right
Right. The steady state, the eigenvector for $\lambda = 1$: $\frac{b}{a + b}$ = {answer}.
:::

::: misses
- [a/(a + b)] That's the fraction of time it's bad.
- [1 - a] That's the chance of staying good for one step.
- [any] Not yet. Balance the flows: (good) × $a$ = (bad) × $b$.
:::
:::

::: check
given: a = 0.1 | 0.15; b = 0.3 | 0.6
answer: ceil(ln(0.01)/ln(1 - a - b))

## For that link ($a$ = {a}, $b$ = {b}), how many steps until the gap to the long-run share is below 1% of where it started?

::: right
Right. The gap shrinks by $1 - a - b$ per step, so you need $(1 - a - b)^k < 0.01$: {answer} steps.
:::

::: misses
- [ceil(ln(0.01)/ln(a + b))] The factor is the second eigenvalue, $1 - a - b$.
- [any] Not yet. Solve $(1 - a - b)^k < 0.01$.
:::
:::

::: check
given: l = 1.5 | 1.1 | 2
answer: ceil(ln(1000)/ln(l))

## A system's largest eigenvalue is {l}. About how many steps until its state has grown 1000-fold?

::: right
Right. $\lambda^k > 1000$ needs $k > \frac{\ln 1000}{\ln\lambda}$: {answer} steps.
:::

::: misses
- [any] Not yet. Solve $\lambda^k = 1000$ and round up.
:::
:::

::: check
given: n = 15 | 20 | 25
answer: round(((1 + sqrt(5))/2)^n/sqrt(5))

## Use $F_n \approx \frac{\varphi^n}{\sqrt 5}$ to find the Fibonacci number $F_{\given{n}}$ (with $F_1 = F_2 = 1$).

::: right
Right. $F_{\given{n}}$ = {answer}; the other eigenvalue's term is so small that rounding gives the exact value.
:::

::: misses
- [any] Not yet. $\varphi = 1.6180340$; compute $\varphi^n/\sqrt 5$ and round.
:::
:::

::: check
kind: choice

## Which matrix cannot be diagonalized?

- [ ] $\begin{bmatrix}2 & 0\\0 & 3\end{bmatrix}$
- [x] $\begin{bmatrix}2 & 1\\0 & 2\end{bmatrix}$
- [ ] $\begin{bmatrix}2 & 1\\0 & 3\end{bmatrix}$
- [ ] $\begin{bmatrix}0 & 1\\1 & 0\end{bmatrix}$

::: right
Right. Its only eigenvalue is 2, repeated, and $A - 2I = \begin{bmatrix}0 & 1\\0 & 0\end{bmatrix}$ has a one-dimensional null space: one eigenvector direction, not two.
:::

::: misses
- [3] Distinct eigenvalues, 2 and 3, guarantee two independent eigenvectors.
- [4] Eigenvalues 1 and $-1$: distinct, so diagonalizable.
- [any] Look for a repeated eigenvalue with too few eigenvectors.
:::
:::

::: check
kind: parts
given: p = 0.1 | 0.2 | 0.3; q = 0.05 | 0.4

## A two-state channel goes from good to bad with probability {p} each second and from bad to good with probability {q}.

::: part
answer: q/(p + q)
tolerance: 0.5%

### What fraction of the time is it good, in the long run?

::: misses
- [p/(p + q)] That's the fraction of time it's bad.
- [any] The eigenvector for $\lambda = 1$ satisfies $p \cdot \text{good} = q \cdot \text{bad}$.
:::
:::

::: part
answer: 1 - p - q
tolerance: 0.5%

### What is the other eigenvalue of $M$?

::: misses
- [any] The trace is $2 - p - q$, and one eigenvalue is 1.
:::
:::
:::

::: check
kind: derivation
vars: n = 1..10

## $A = \begin{bmatrix}2 & 0\\0 & 0.5\end{bmatrix}$ is already diagonal.

::: step
answer: 2^n

### What is the first entry of $A^n(1, 1)$?
:::

::: step
answer: 0.5^n

### And the second?
:::

::: right
Right. Powers of a diagonal matrix just power its entries; diagonalizing turns every matrix power into this.
:::
:::

::: explain
## Why does the largest eigenvalue (in size) decide the long-run behavior of $\mathbf{u}_{k+1} = A\mathbf{u}_k$?

::: model
Write the starting vector as a combination of eigenvectors. Each step multiplies each eigenvector's piece by its own eigenvalue, so after $k$ steps the pieces are scaled by $\lambda_i^k$. Powers of numbers of different sizes separate quickly: the piece with the largest $|\lambda|$ outgrows all the others, so the state ends up pointing along that eigenvector and growing or shrinking by that factor each step. The second largest $|\lambda|$ sets how fast the other pieces fade relative to it.
:::
:::

::: practice

::: check
given: a = 0.02 | 0.1; b = 0.2 | 0.5
answer: a/(a + b)
tolerance: 0.5%

## A link goes bad with probability {a} per step and recovers with probability {b}. In the long run, what fraction of the time is it bad?

::: misses
- [b/(a + b)] That's the fraction good.
- [any] $\frac{a}{a + b}$.
:::
:::

::: check
given: p = 2 | 3; q = 0.5 | 0.25; k = 4 | 6
answer: p^k + q^k
tolerance: 0.5%

## $A$ has eigenvalues {p} and {q}. What is the trace of $A^{\given{k}}$?

::: misses
- [(p + q)^k] The eigenvalues of $A^k$ are $\lambda^k$; the trace adds them.
- [any] Trace = sum of the eigenvalues of $A^k$.
:::
:::

::: check
given: p = 2 | 4; q = 3 | 0.5
answer: p*q

## $A$ has eigenvalues {p} and {q}. What is $\det A$?

::: misses
- [p + q] That's the trace.
- [any] The product of the eigenvalues.
:::
:::
:::
