---
title: The four subspaces of a circuit
heading: Kirchhoff's laws are linear algebra
eyebrow: A7 · Lesson 19 · The four subspaces
xp: 50
---

::: hook
Write down which branches of a circuit connect which nodes, as a matrix of $+1$s and $-1$s, and you've captured its whole structure. That one **incidence matrix** contains Kirchhoff's current law, Kirchhoff's voltage law, the number of independent loops, the reason one node must be grounded, and the conductance matrix of nodal analysis. Every matrix has four fundamental subspaces, and for a circuit each one has a physical meaning.
:::

::: play
- The circuit has four nodes (in, a, b and ground) and five branches. The meters read the branch currents into and out of node a.
- Change $R_3$ and the source. Whatever you do, the current in $R_1$ equals the currents in $R_2$ and $R_3$ added together. That's KCL at node a, and in this lesson it becomes $A^T\mathbf{y} = \mathbf{0}$.
:::
:::

```sim circuit
V1 in 0 10          @ 0,0 down
R1 in a 1k          @ 0,0 right
R2 a 0 2k           @ 2,0 down
R3 a b 1k           @ 2,0 right
R4 b 0 2k           @ 4,0 down
slider: V1.amp 1..20
slider: R3 100..10k log
meter: i(R1), i(R2), i(R3), v(a), v(b)
```

::: predict
## A connected circuit has 4 nodes and 6 branches. How many independent loops does it have?

- [ ] 2
- [x] 3
- [ ] 4
- [ ] 6

::: reveal
Three: $m - n + 1 = 6 - 4 + 1$. Building the circuit one branch at a time, the first $n - 1 = 3$ branches can connect all the nodes without closing a loop (a tree), and every branch after that closes exactly one new loop. This count is the dimension of a null space, as you'll see.
:::
:::

::: nameit
## The four subspaces

For an $m \times n$ matrix $A$ of rank $r$:

| Subspace | Lives in | Dimension |
|---|---|---|
| Column space $C(A)$ | $\mathbb{R}^m$ | $r$ |
| Null space $N(A)$ | $\mathbb{R}^n$ | $n - r$ |
| Row space $C(A^T)$ | $\mathbb{R}^n$ | $r$ |
| Left null space $N(A^T)$ | $\mathbb{R}^m$ | $m - r$ |

The row space and null space are perpendicular, and so are the column space and left null space (lesson 24).

## The incidence matrix

Number the branches $1, \ldots, m$ and the nodes $1, \ldots, n$, and give each branch a direction. Row $k$ of the $m \times n$ incidence matrix $A$ has $-1$ in the column of branch $k$'s starting node and $+1$ in its ending node. For a square of 4 nodes with one diagonal:

$$A = \begin{bmatrix}-1 & 1 & 0 & 0\\-1 & 0 & 1 & 0\\0 & -1 & 1 & 0\\0 & -1 & 0 & 1\\0 & 0 & -1 & 1\end{bmatrix} \quad \begin{matrix}\text{branch 1: } 1 \to 2\\ \text{branch 2: } 1 \to 3\\ \text{branch 3: } 2 \to 3\\ \text{branch 4: } 2 \to 4\\ \text{branch 5: } 3 \to 4\end{matrix}$$

## What each subspace means

- **$A\mathbf{x}$**, for node voltages $\mathbf{x}$, gives the voltage across each branch.
- **Null space $N(A)$:** voltages with no differences anywhere, $\mathbf{x} = (c, c, c, c)$. Raising every node by the same amount changes nothing, which is why you must **ground** a node to fix the voltages. For a connected circuit $N(A)$ is 1D, so $r = n - 1$.
- **Column space $C(A)$:** the branch voltages a circuit can actually have. A set of branch voltages is possible exactly when it adds to zero around every loop: that's **KVL**.
- **Left null space $N(A^T)$:** branch currents $\mathbf{y}$ with $A^T\mathbf{y} = \mathbf{0}$. Row $j$ of $A^T\mathbf{y}$ is the net current into node $j$, so this is **KCL**. Its dimension $m - r = m - n + 1$ is the number of independent loops: each loop current is a basis vector.
- **Row space $C(A^T)$:** the possible net current injections at the nodes; they must add to zero, since current that goes in must come out.

## Nodal analysis

With branch conductances on the diagonal of $C$, Ohm's law is $\mathbf{y} = C(A\mathbf{x})$ and KCL with injected currents $\mathbf{f}$ is $A^T\mathbf{y} = \mathbf{f}$. Together:

$$A^TCA\,\mathbf{x} = \mathbf{f}$$

$A^TCA$ is the conductance matrix $G$ from lesson 12, built from the circuit's structure. Grounding a node deletes its column, which removes the null space and makes $G$ invertible.
:::

::: example
## Find a basis for the loop currents of the square with a diagonal above.

::: solution
1. **Count the loops.**
   $$\begin{aligned} m - n + 1 &= 5 - 4 + 1 \\ &= 2 \end{aligned}$$
2. **Loop 1.** It goes $1 \to 2 \to 3$ and back to 1 against branch 2:
   $$\mathbf{y} = (1, -1, 1, 0, 0)$$
3. **Loop 2.** It goes $2 \to 3 \to 4$ and back to 2 against branch 4:
   $$\mathbf{y} = (0, 0, 1, -1, 1)$$
4. **Check loop 1 at node 2.** Branch 1 brings $+1$ in, branch 3 takes $1$ out, net zero. Each column of $A^T\mathbf{y}$ balances the same way.

**Answer:** the two loops $(1, -1, 1, 0, 0)$ and $(0, 0, 1, -1, 1)$ are a basis for the loop currents.
:::
:::

::: example
## With every branch a 1 S conductance and node 4 grounded, find $G = A^TCA$.

::: solution
1. **Ground node 4.** Drop column 4 and use $C = I$.
2. **Read off $A^TA$.** It has each node's number of branches on the diagonal and $-1$ for each branch joining two nodes:
   $$G = \begin{bmatrix}2 & -1 & -1\\-1 & 3 & -1\\-1 & -1 & 3\end{bmatrix}$$
3. **Compare with KCL.** That's exactly what writing KCL node by node would give: the matrix product does the bookkeeping.

**Answer:** $G$ has rows $(2, -1, -1)$, $(-1, 3, -1)$ and $(-1, -1, 3)$.
:::
:::

::: example
## A connected circuit has 5 nodes and 8 branches. What are the dimensions of its incidence matrix's four subspaces, and how many independent loops does it have?

::: solution
1. **Size and rank.** The incidence matrix $A$ is 8 × 5, one row per branch. For a connected graph its null space is the constant potentials, dimension 1, so the rank is $5 - 1 = 4$.
2. **The four subspaces.**

| Subspace | Dimension |
|---|---|
| column space | 4, in $\mathbb{R}^8$ |
| row space | 4, in $\mathbb{R}^5$ |
| null space | 1 (raise every node by the same voltage) |
| left null space | $8 - 4 = 4$ |

3. **Loops.** The left null space holds the currents that satisfy KCL with no sources: the loop currents. So there are 4 independent loops, the $b - n + 1$ of mesh analysis.

**Answer:** the column space and row space have dimension 4, the null space 1 and the left null space 4, so the circuit has 4 independent loops.
:::
:::

::: check
given: n = 4 | 6 | 10; extra = 2 | 5; let m = n + extra
answer: extra + 1

## A connected circuit has {n} nodes and {m} branches. How many independent loops does it have?

::: right
Right. $m - n + 1$ = {answer}, the dimension of the left null space.
:::

::: misses
- [extra] Add one: a tree needs only $n - 1$ branches, so $m - (n - 1)$ branches close loops.
- [any] Not yet. $m - n + 1$.
:::
:::

::: check
given: n = 5 | 8 | 12
answer: n - 1

## What is the rank of the incidence matrix of a connected circuit with {n} nodes?

::: right
Right. The null space is the 1D line of equal voltages, so $r = n - 1$ = {answer}.
:::

::: misses
- [n] The columns add to zero (each row has one $+1$ and one $-1$), so they're dependent.
- [any] Not yet. What's the dimension of the null space?
:::
:::

::: check
given: R1 = 1 | 2; R2 = 2 | 4; R3 = 1 | 5
answer: 1/R1 + 1/R2 + 1/R3
unit: mS
tolerance: 0.5%

## A node has three resistors attached: {R1} kΩ, {R2} kΩ and {R3} kΩ. What is its diagonal entry of $G = A^TCA$, in mS?

::: right
Right. The diagonal entry adds the conductances of every branch touching the node: {answer}.
:::

::: misses
- [R1 + R2 + R3] Conductances add, not resistances.
- [1/(R1 + R2 + R3)] Each branch contributes its own conductance.
- [any] Not yet. Add $1/R$ for each attached resistor.
:::
:::

::: check
given: i1 = 5 | 8; i2 = 2 | 3
answer: i1 - i2
unit: mA

## At node a, {i1} mA arrives through $R_1$ and {i2} mA leaves through $R_2$. How much leaves through $R_3$?

::: right
Right. KCL, one row of $A^T\mathbf{y} = \mathbf{0}$: {answer}.
:::

::: misses
- [i1 + i2] What comes in must go out: subtract what $R_2$ takes.
- [any] Not yet. Net current into the node is zero.
:::
:::

::: check
given: m = 5 | 7; n = 3 | 4; r = 2 | 3
answer: m - r

## An {m} × {n} matrix has rank {r}. What is the dimension of its left null space, $N(A^T)$?

::: right
Right. $m - r$ = {answer}.
:::

::: misses
- [n - r] That's the null space $N(A)$, in $\mathbb{R}^n$.
- [any] Not yet. The left null space lives in $\mathbb{R}^m$.
:::
:::

::: check
kind: choice

## Why must one node of a circuit be grounded before solving for node voltages?

- [x] The incidence matrix has a null space: adding the same voltage to every node changes no branch voltage
- [ ] Without ground, KCL fails
- [ ] Ground supplies the current
- [ ] The conductance matrix would be too big to solve

::: right
Right. Only voltage differences are physical. Grounding a node fixes the arbitrary constant, which removes the null space.
:::

::: misses
- [2] KCL holds regardless. The trouble is that the node voltages aren't unique.
- [any] What happens to $A\mathbf{x}$ if you add 1 V to every node?
:::
:::

::: check
kind: parts
given: n = 4 | 5 | 6; b = 8 | 9 | 10

## A connected circuit has {n} nodes and {b} branches.

::: part
answer: n - 1
tolerance: 0

### What is the rank of its incidence matrix?

::: misses
- [n] The constant potentials are in the null space, so the rank is one less.
- [any] Rank = nodes − 1.
:::
:::

::: part
answer: b - n + 1
tolerance: 0

### How many independent loops does it have?

::: misses
- [b - n] One more: the rank is $n - 1$.
- [any] Branches minus the rank.
:::
:::
:::

::: check
kind: derivation
vars: m = 5..10, n = 5..10, r = 1..4

## An $m \times n$ matrix has rank $r$.

::: step
answer: n - r

### What is the dimension of its null space?
:::

::: step
answer: m - r

### What is the dimension of its left null space?
:::

::: right
Right. Row space and null space split $\mathbb{R}^n$; column space and left null space split $\mathbb{R}^m$.
:::
:::

::: explain
## Explain why the branch currents of a circuit satisfy KCL exactly when they're in the left null space of its incidence matrix.

::: model
Column $j$ of the incidence matrix has a $+1$ for each branch that ends at node $j$ and a $-1$ for each branch that starts there. So entry $j$ of $A^T\mathbf{y}$ adds up the currents flowing into node $j$ and subtracts those flowing out: it's the net current into the node. $A^T\mathbf{y} = \mathbf{0}$ says the net current into every node is zero, which is exactly Kirchhoff's current law. The currents that satisfy it form the left null space, and its basis vectors are the loop currents.
:::
:::

::: practice

::: check
given: n = 5 | 7; m = 8 | 12
answer: m - n + 1

## A connected circuit has {n} nodes and {m} branches. How many independent loops?

::: misses
- [m - n] Add one.
- [any] $m - n + 1$.
:::
:::

::: check
given: g1 = 1 | 2; g2 = 3 | 0.5
answer: -g2

## Nodes 1 and 2 are joined by a branch of {g2} mS (and node 1 also has {g1} mS to ground). What is entry $(1, 2)$ of $G$?

::: misses
- [g2] Off-diagonal entries are negative.
- [any] Minus the conductance joining the two nodes.
:::
:::

::: check
given: m = 6 | 9; r = 3 | 4
answer: r

## An {m} × 5 matrix has rank {r}. What is the dimension of its row space?

::: misses
- [5 - r] That's the null space.
- [any] The row space has the same dimension as the column space.
:::
:::
:::
