---
title: Inverses and transposes
heading: Undoing a matrix, and flipping it
eyebrow: A7 · Lesson 11 · Inverses and transposes
xp: 40
---

::: hook
Inject a current into node 1 of a resistor network and measure the voltage at node 2. Now inject the same current into node 2 and measure at node 1. You get exactly the same voltage, every time, however lopsided the network. This is **reciprocity**, and it's a fact about matrices: a resistor network's conductance matrix equals its own **transpose**, and so does its **inverse**, which is the matrix that answers "inject here, measure there".
:::

::: play
- The solid curve is the unit circle after matrix $A$; the dashed curve is the unit circle after $A^{-1}$.
- The green arrow is a vector $\mathbf{x}$ moved by $A$; the dashed arrow is that result moved back by $A^{-1}$. It always lands on the start.
- Shrink the determinant toward zero. What happens to the inverse's ellipse?
:::
:::

```sim plot
view: complex
range: 2.5
slider: a = -2..2 step 0.1 = 1.5
slider: b = -2..2 step 0.1 = 0.5
slider: c = -2..2 step 0.1 = 0.3
slider: d = -2..2 step 0.1 = 1
curve: (a*cos(u) + b*sin(u)) + j*(c*cos(u) + d*sin(u)) | over: u = 0..2*pi | label: A
curve: (d*cos(u) - b*sin(u))/(a*d - b*c) + j*(-c*cos(u) + a*sin(u))/(a*d - b*c) | over: u = 0..2*pi | dashed | color: ch2 | label: A⁻¹
arrow: 1 + 0.5*j | label: x
arrow: (a + 0.5*b) + j*(c + 0.5*d) | color: ch3 | label: Ax
readout: det = a*d - b*c | digits: 3
```

::: predict
## A matrix squashes the plane flat, onto a line. Can any matrix undo it?

- [ ] Yes, its inverse
- [x] No: many points land on the same spot, and nothing can tell them apart afterward
- [ ] Only if it's symmetric
- [ ] Yes, if you use its transpose

::: reveal
No. Squashing onto a line sends whole lines of points to single points, so information is lost. An inverse would have to send one point back to many, which no matrix can do. That's exactly when the determinant is zero, and the inverse's ellipse in the sim blows up as you approach it.
:::
:::

::: nameit
## The inverse

$A^{-1}$ is the matrix with $A^{-1}A = AA^{-1} = I$: it undoes $A$. It exists exactly when $A$ is square with nonzero determinant, which is the same as having $n$ nonzero pivots. For 2 × 2,

$$\begin{bmatrix}a & b\\c & d\end{bmatrix}^{-1} = \frac{1}{ad - bc}\begin{bmatrix}d & -b\\-c & a\end{bmatrix}$$

swap the diagonal, negate the off-diagonal, divide by the determinant. For bigger matrices, **Gauss-Jordan** elimination on $[A \mid I]$ turns it into $[I \mid A^{-1}]$.

**Order reverses for products:** $(AB)^{-1} = B^{-1}A^{-1}$. To undo "B then A", undo A first.

**Don't invert to solve.** Computing $A^{-1}$ and then $A^{-1}\mathbf{b}$ costs about three times as much as solving with LU, and is less accurate. Use the inverse as an idea, and `solve` in code.

## The transpose

$A^T$ flips $A$ across its diagonal: $(A^T)_{ij} = a_{ji}$, so rows become columns. Its rules:

$$(AB)^T = B^TA^T \qquad (A^T)^{-1} = (A^{-1})^T \qquad \mathbf{x} \cdot \mathbf{y} = \mathbf{x}^T\mathbf{y}$$

A matrix with $A^T = A$ is **symmetric**. The inverse of a symmetric matrix is symmetric too.

## Permutation matrices

A **permutation matrix** reorders rows: it's the identity with its rows shuffled. Undoing a shuffle is shuffling back, and $P^{-1} = P^T$.

## Reciprocity

In nodal analysis (lesson 12), a resistor between nodes $i$ and $j$ puts $-\frac{1}{R}$ in both entry $(i, j)$ and entry $(j, i)$ of the conductance matrix $G$, so $G$ is symmetric. The node voltages are $\mathbf{v} = G^{-1}\mathbf{i}$, and entry $(j, i)$ of $G^{-1}$ is the voltage at $j$ per unit current injected at $i$. Since $G^{-1}$ is symmetric, swapping the two nodes gives the same answer.
:::

::: example
## Invert $\begin{bmatrix}4 & 7\\2 & 6\end{bmatrix}$.

::: solution
1. **Determinant.**
   $$\begin{aligned} \det &= 4 \times 6 - 7 \times 2 \\ &= 10 \end{aligned}$$
2. **Swap, negate, divide.**
   $$\begin{aligned} &\frac{1}{10}\begin{bmatrix}6 & -7\\-2 & 4\end{bmatrix} \\ &= \begin{bmatrix}0.6 & -0.7\\-0.2 & 0.4\end{bmatrix} \end{aligned}$$
3. **Check the top-left entry of the product.**
   $$\begin{aligned} 4(0.6) + 7(-0.2) &= 2.4 - 1.4 \\ &= 1 \end{aligned}$$

**Answer:** the inverse is $\begin{bmatrix}0.6 & -0.7\\-0.2 & 0.4\end{bmatrix}$.
:::
:::

::: example
## Three 1 kΩ resistors: node 1 to ground, node 1 to node 2, node 2 to ground. Show reciprocity.

::: solution
1. **Conductance matrix.** In mS:
   $$G = \begin{bmatrix}2 & -1\\-1 & 2\end{bmatrix}$$
   with determinant 3.
2. **Invert it.**
   $$G^{-1} = \frac{1}{3}\begin{bmatrix}2 & 1\\1 & 2\end{bmatrix}\ \text{k}\Omega$$
3. **Inject at each node.** 1 mA into node 1 gives $v_2 = \frac{1}{3}$ V; 1 mA into node 2 gives $v_1 = \frac{1}{3}$ V.
4. **Why they match.** The two off-diagonal entries are equal because $G$ is symmetric.

**Answer:** 1 mA into either node gives $\frac13$ V at the other, which is reciprocity.
:::
:::

::: example
## Invert $L = \begin{bmatrix}1 & 0 & 0\\2 & 1 & 0\\4 & 3 & 1\end{bmatrix}$, the $L$ from an elimination.

::: solution
1. **What $L^{-1}$ does.** $L$ undoes the elimination steps, so $L^{-1}$ redoes them: subtract 2 × row 1 from row 2, then 4 × row 1 and 3 × row 2 from row 3.
2. **Apply those steps to $I$.**
   $$L^{-1} = \begin{bmatrix}1 & 0 & 0\\-2 & 1 & 0\\2 & -3 & 1\end{bmatrix}$$
3. **The corner entry.** It is
   $$2 \cdot 3 - 4 = 2$$
   not $-4$: the steps interact.
4. **Why keep $L$.** That's why $L$, which stores the multipliers directly, is the convenient one to keep.

**Answer:** $L^{-1}$ has rows $(1, 0, 0)$, $(-2, 1, 0)$ and $(2, -3, 1)$.
:::
:::

::: check
given: a = 4 | 3; b = 7 | 1; c = 2 | -1; d = 6 | 5
answer: d/(a*d - b*c)
tolerance: 0.5%

## What is the top-left entry of $\begin{bmatrix}\given{a} & \given{b}\\\given{c} & \given{d}\end{bmatrix}^{-1}$?

::: right
Right. $\frac{d}{ad - bc}$ = {answer}.
:::

::: misses
- [1/a] Inverting a matrix isn't inverting its entries.
- [a/(a*d - b*c)] Swap the diagonal entries: the top-left gets $d$.
- [any] Not yet. Swap the diagonal, negate the off-diagonal, divide by the determinant.
:::
:::

::: check
given: a = 4 | 3; b = 7 | 1; c = 2 | -1; d = 6 | 5
answer: -b/(a*d - b*c)
tolerance: 0.5%

## What is the top-right entry of $\begin{bmatrix}\given{a} & \given{b}\\\given{c} & \given{d}\end{bmatrix}^{-1}$?

::: right
Right. $\frac{-b}{ad - bc}$ = {answer}.
:::

::: misses
- [b/(a*d - b*c)] Negate the off-diagonal entries.
- [-c/(a*d - b*c)] The off-diagonal entries stay in place; only their signs change.
- [any] Not yet. The top-right entry is $-b$ over the determinant.
:::
:::

::: check
kind: choice

## What is $(AB)^{-1}$?

- [ ] $A^{-1}B^{-1}$
- [x] $B^{-1}A^{-1}$
- [ ] $(BA)^{-1}$
- [ ] $A^TB^T$

::: right
Right. $AB$ applies $B$ then $A$; to undo it, undo $A$ first, then $B$.
:::

::: misses
- [1] That undoes them in the wrong order. Check: $(AB)(A^{-1}B^{-1})$ doesn't simplify.
- [4] Transposes aren't inverses, except for special matrices.
- [any] Undo the last step first.
:::
:::

::: check
kind: choice

## What is $(AB)^T$?

- [ ] $A^TB^T$
- [x] $B^TA^T$
- [ ] $AB$
- [ ] $(BA)^{-1}$

::: right
Right. Like the inverse, the transpose of a product reverses the order.
:::

::: misses
- [1] The sizes may not even match: for $3 \times 2$ times $2 \times 4$, $A^TB^T$ is $2 \times 3$ times $4 \times 2$.
- [any] Check the sizes.
:::
:::

::: check
given: R1 = 1 | 2; R2 = 1 | 3; R3 = 2 | 4
answer: (1/R2)/((1/R1 + 1/R2)*(1/R2 + 1/R3) - 1/R2^2)
unit: V
tolerance: 0.5%

## Resistors: {R1} kΩ from node 1 to ground, {R2} kΩ from node 1 to node 2, {R3} kΩ from node 2 to ground. Inject 1 mA into node 2. What is the voltage at node 1?

::: right
Right. It's the off-diagonal entry of $G^{-1}$, which by reciprocity equals the voltage at node 2 for 1 mA into node 1: {answer}.
:::

::: misses
- [(1/R1 + 1/R2)/((1/R1 + 1/R2)*(1/R2 + 1/R3) - 1/R2^2)] That's the diagonal entry, the voltage at node 2 itself.
- [any] Not yet. Build $G$ in mS, invert it, and read the off-diagonal entry in kΩ.
:::
:::

::: check
kind: choice

## $P$ is a permutation matrix. What is $P^{-1}$?

- [x] $P^T$
- [ ] $P$ itself, always
- [ ] $-P$
- [ ] It may not exist

::: right
Right. Shuffling back is the transpose. $P^{-1} = P$ only for a shuffle that is its own undo, like a single swap.
:::

::: misses
- [2] True for a single swap, but a 3-cycle needs the reverse cycle.
- [4] A shuffle can always be undone.
- [any] Undoing a shuffle is another shuffle.
:::
:::

::: check
kind: parts
given: a = 2 | 3 | 5; b = 1 | 4

## Invert $A = \begin{bmatrix}\given{a} & 1\\1 & \given{b}\end{bmatrix}$.

::: part
answer: b/(a*b - 1)
tolerance: 0.5%

### What is the top-left entry of $A^{-1}$?

::: misses
- [a/(a*b - 1)] Swap the diagonal entries.
- [1/a] Inverting a matrix doesn't invert its entries one by one.
- [any] $\frac{1}{ad - bc}\begin{bmatrix}d & -b\\-c & a\end{bmatrix}$.
:::
:::

::: part
answer: -1/(a*b - 1)
tolerance: 0.5%

### What is the top-right entry?

::: misses
- [1/(a*b - 1)] The off-diagonal entries change sign.
- [any] $\frac{-1}{ab - 1}$.
:::
:::
:::

::: check
kind: derivation
vars: t = 0.1..3

## Invert the rotation $R = \begin{bmatrix}\cos t & -\sin t\\\sin t & \cos t\end{bmatrix}$.

::: step
answer: sin(t)

### Rotating back by $-t$ undoes it. What is the top-right entry of $R^{-1}$?
:::

::: step
answer: -sin(t)

### And the bottom-left entry?
:::

::: right
Right. $R^{-1} = R^T$: for a rotation, the inverse is the transpose.
:::
:::

::: explain
## In code, why do you solve $A\mathbf{x} = \mathbf{b}$ with a solver instead of computing $A^{-1}$ and multiplying?

::: model
Computing the full inverse takes about three times as many operations as an LU factorization, and then you still multiply by $\mathbf{b}$. It also loses more accuracy to rounding, because the inverse's entries can be large and cancel. A solver factors $A$ once and uses forward and back substitution, which is faster and more accurate. The inverse is a useful idea for reasoning, like reciprocity, but rarely the right thing to compute.
:::
:::

::: practice

::: check
given: a = 2 | 5; b = 1 | 3; c = 3 | 4; d = 7 | 9
answer: a/(a*d - b*c)
tolerance: 0.5%

## What is the bottom-right entry of $\begin{bmatrix}\given{a} & \given{b}\\\given{c} & \given{d}\end{bmatrix}^{-1}$?

::: misses
- [d/(a*d - b*c)] That's the top-left entry.
- [any] Swap the diagonal: the bottom-right gets $a$.
:::
:::

::: check
given: k = 2 | 4 | 5
answer: 1/k

## What is the top-left entry of $\begin{bmatrix}\given{k} & 0\\0 & 3\end{bmatrix}^{-1}$?

::: misses
- [k] Invert the scaling.
- [any] A diagonal matrix inverts entry by entry.
:::
:::

::: check
given: a = 1 | 2; b = 3 | 5
answer: b

## $A = \begin{bmatrix}\given{a} & \given{b}\\7 & 1\end{bmatrix}$. What is the bottom-left entry of $A^T$?

::: misses
- [7] That's the bottom-left of $A$. The transpose swaps it with the top-right.
- [any] $(A^T)_{21} = a_{12}$.
:::
:::
:::
