---
title: Rank and the complete solution
heading: None, one, or infinitely many
eyebrow: A7 · Lesson 16 · Rank
xp: 40
---

::: hook
Five sensors measure three unknowns: more equations than unknowns, and with real measurement noise, probably no exact solution at all. Two equations describe four currents: fewer equations than unknowns, and infinitely many solutions. Whether a linear system has no solution, exactly one, or infinitely many is decided by a single number, the matrix's **rank**, together with where $\mathbf{b}$ sits. This lesson gives you the whole picture.
:::

::: play
- The two lines are $x + 2y = 4$ and $a x + 4y = c$, the row picture of a 2 × 2 system.
- With $a \ne 2$ they cross once: one solution. Set $a = 2$ to make them parallel. Now move $c$.
- At what value of $c$ do the parallel lines become the same line?
:::
:::

```sim plot
view: graph
x: x = -4..8
y: y = -4..6
slider: a = 0..4 step 0.1 = 1
slider: c = 0..12 step 0.5 = 6
plot: (4 - x)/2 | label: x + 2y = 4
plot: (c - a*x)/4 | label: ax + 4y = c | color: ch2
readout: determinant = 4 - 2*a | digits: 3
readout: rank = 1 + step(abs(a - 2) - 0.05)
```

::: predict
## $x + 2y = 4$ and $2x + 4y = c$. For which $c$ are there infinitely many solutions?

- [ ] Every $c$
- [x] Only $c = 8$
- [ ] Only $c = 4$
- [ ] None

::: reveal
Only $c = 8$. The second equation's left side is twice the first's, so the system is consistent only if $c$ is twice 4. Then the two equations say the same thing, and every point on the line is a solution. For any other $c$ there's no solution at all: the lines are parallel and apart.
:::
:::

::: nameit
## Echelon form and rank

Elimination turns $A$ into an **echelon form**: each row's first nonzero entry (its **pivot**) is to the right of the row above's, with zero rows at the bottom. Going further, making each pivot 1 and clearing above it, gives the **reduced row echelon form**, $R$.

The **rank** $r$ is the number of pivots. Columns with pivots are **pivot columns**; the rest are **free columns**, and their variables are **free variables**: you can set them to anything.

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

- the column space has dimension $r$;
- the null space has dimension $n - r$, one direction per free variable.

## The complete solution

Every solution of $A\mathbf{x} = \mathbf{b}$ has the form

$$\mathbf{x} = \mathbf{x}_p + \mathbf{x}_n$$

where $\mathbf{x}_p$ is any one particular solution (set the free variables to 0 and solve) and $\mathbf{x}_n$ is anything in the null space.

## The four cases

| Rank | Shape | Solutions of $A\mathbf{x} = \mathbf{b}$ |
|---|---|---|
| $r = m = n$ | square, invertible | exactly one, for every $\mathbf{b}$ |
| $r = n < m$ | tall, full column rank | zero or one |
| $r = m < n$ | wide, full row rank | infinitely many, for every $\mathbf{b}$ |
| $r < m$, $r < n$ | neither | zero or infinitely many |

"Zero" happens when elimination produces a row $0 = $ (something nonzero). Tall systems, like many noisy measurements of a few unknowns, usually have no exact solution; lesson 27's least squares finds the best one.
:::

::: example
## Find the rank and null space of $A = \begin{bmatrix}1 & 2 & 1\\2 & 4 & 3\end{bmatrix}$.

::: solution
1. **Eliminate.** Row 2 minus twice row 1 gives $(0, 0, 1)$.
2. **Clear above the pivot.** Row 1 minus row 2 gives $(1, 2, 0)$, so
   $$R = \begin{bmatrix}1 & 2 & 0\\0 & 0 & 1\end{bmatrix}$$
3. **Rank.** The pivots are in columns 1 and 3, so $r = 2$, and column 2 is free.
4. **Null space.** With $y = 1$: $z = 0$, $x = -2$. The null space is the multiples of $(-2, 1, 0)$, dimension $3 - 2 = 1$.

**Answer:** the rank is 2, and the null space is the line of multiples of $(-2, 1, 0)$.
:::
:::

::: example
## Find the complete solution of $x + 2y + z = 4$, $2x + 4y + 3z = 10$.

::: solution
1. **Eliminate the augmented rows.** The same steps give $z = 2$ and $x + 2y = 2$.
2. **Particular solution.** Setting the free $y = 0$ gives $\mathbf{x}_p = (2, 0, 2)$.
3. **Add the null space.**
   $$\mathbf{x} = (2, 0, 2) + y(-2, 1, 0)$$
   a line of solutions in 3D.

**Answer:** $\mathbf{x} = (2, 0, 2) + y(-2, 1, 0)$ for any $y$, a line of solutions.
:::
:::

::: example
## For which $c$ does $x + y = 2$, $2x + cy = 4$ have infinitely many solutions?

::: solution
1. **Eliminate.** Subtracting 2 × row 1 from row 2 leaves
   $$(c - 2)y = 0$$
2. **If $c \ne 2$.** That forces $y = 0$ and then $x = 2$: one solution, rank 2.
3. **If $c = 2$.** The second row becomes $0 = 0$: the rank drops to 1, $y$ is free, and every point on $x + y = 2$ is a solution.
4. **Why it's consistent.** The right side 4 happens to be twice 2. With a right side of 5 instead, $c = 2$ would give $0 = 1$ and no solution.

**Answer:** only $c = 2$ gives infinitely many solutions: every point on $x + y = 2$.
:::
:::

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

## A {m} × {n} matrix has rank {r}. What is the dimension of its null space?

::: right
Right. One direction per free variable: $n - r$ = {answer}.
:::

::: misses
- [m - r] Free variables come from columns: $n - r$.
- [r] That's the dimension of the column space.
- [any] Not yet. Count the free columns.
:::
:::

::: check
given: c1 = 4 | 7; c2 = 2 | -1
answer: c1 - c2

## After elimination, a system reads $x + 2y + z = \given{c1}$ and $z = \given{c2}$, with $y$ free. Setting $y = 0$, what is $x$ in the particular solution?

::: right
Right. $z = \given{c2}$, so $x = c_1 - z$ = {answer}.
:::

::: misses
- [c1] Subtract $z$ = {c2}.
- [c1 + c2] Move $z$ to the other side: subtract it.
- [any] Not yet. Use $z$ = {c2} in the first equation.
:::
:::

::: check
given: p = 2 | 3; c1 = 4 | 5
answer: 2*c1

## For which $c$ is the system $x + \given{p}y = \given{c1}$, $2x + 2\given{p}y = c$ consistent?

::: right
Right. The second left side is twice the first, so $c$ must be $2 \times$ {c1} = {answer}.
:::

::: misses
- [c1] The second equation is doubled, so its right side must be too.
- [any] Not yet. Compare the second equation with twice the first.
:::
:::

::: check
kind: choice

## A 3 × 5 matrix has rank 3. What can you say about $A\mathbf{x} = \mathbf{b}$?

- [x] It has infinitely many solutions for every $\mathbf{b}$
- [ ] It has exactly one solution for every $\mathbf{b}$
- [ ] It has no solution for most $\mathbf{b}$
- [ ] It has zero or one solution

::: right
Right. Rank equals the number of rows, so every $\mathbf{b}$ is reachable, and the $5 - 3 = 2$ free variables give infinitely many solutions.
:::

::: misses
- [2] Two free variables mean a 2D family of solutions.
- [3] With $r = m$, the column space is all of $\mathbb{R}^3$.
- [any] Compare $r$ with $m$ and with $n$.
:::
:::

::: check
kind: choice

## Five noisy sensor readings give five equations in three unknowns, and the 5 × 3 matrix has rank 3. How many exact solutions are there, usually?

- [x] None, though there could be one
- [ ] Exactly one
- [ ] Infinitely many
- [ ] Five

::: right
Right. With $r = n < m$ there's at most one solution, and noise almost always pushes $\mathbf{b}$ out of the 3D column space. Least squares finds the closest fit instead.
:::

::: misses
- [2] Only if the readings happen to be perfectly consistent.
- [3] Full column rank means no free variables, so never infinitely many.
- [any] Compare the rank with the number of equations and unknowns.
:::
:::

::: check
given: k = 2 | 3 | 5
answer: 1

## What is the rank of $\begin{bmatrix}1 & \given{k}\\\given{k} & \given{k}^2\end{bmatrix}$?

::: right
Right. Row 2 is {k} times row 1, so there's one pivot.
:::

::: misses
- [2] Row 2 is {k} times row 1: elimination leaves a zero row.
- [any] Not yet. Eliminate and count the pivots.
:::
:::

::: check
kind: parts
given: c = 3 | 4 | 6

## Consider $x + 2y = \given{c}$, $2x + 4y = d$.

::: part
answer: 2*c
tolerance: 0.5%

### For which $d$ does it have solutions?

::: misses
- [c/2] Row 2 is twice row 1, so its right side must be twice too.
- [any] Eliminate: $0 = d - 2c$.
:::
:::

::: part
answer: c - 2
tolerance: 0.5%

### With that $d$, the solution with $y = 1$ has $x$ = ?

::: misses
- [c] Remember the $2y$.
- [any] $x = c - 2y$.
:::
:::
:::

::: check
kind: derivation
vars: c = 1..5, t = -2..2

## Solve $x + y + z = c$, $x - y = 0$, with $z = t$ free.

::: step
answer: (c - t)/2

### What is $x$?
:::

::: step
answer: (c - t)^2/2 + t^2

### What is $x^2 + y^2 + z^2$ for that solution?
:::

::: right
Right. Rank 2 in three unknowns leaves one free variable, so the solutions form a line.
:::
:::

::: explain
## Why is every solution of $A\mathbf{x} = \mathbf{b}$ a particular solution plus something from the null space?

::: model
If $\mathbf{x}_p$ and $\mathbf{x}$ both solve $A\mathbf{x} = \mathbf{b}$, then $A(\mathbf{x} - \mathbf{x}_p) = \mathbf{b} - \mathbf{b} = \mathbf{0}$, so their difference is in the null space. Turned around, adding any null-space vector to $\mathbf{x}_p$ leaves $A\mathbf{x}$ unchanged, so it's still a solution. The solutions are exactly one particular solution shifted by every null-space vector: a single point if the null space is just zero, otherwise a line, plane or larger flat set.
:::
:::

::: practice

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

## A {m} × {n} matrix has rank {r}. What is the dimension of its column space?

::: misses
- [n - r] That's the null space.
- [any] It equals the rank.
:::
:::

::: check
given: a = 2..9 int
answer: 2*a

## For which $k$ does $\begin{bmatrix}1 & 2\\\given{a} & k\end{bmatrix}$ have rank 1?

::: misses
- [a/2] Row 2 must be {a} times row 1.
- [any] Make row 2 a multiple of row 1.
:::
:::

::: check
given: c1 = 6 | 9; c2 = 1 | 3
answer: c1 - 2*c2

## After elimination: $x + 2y + 3z = \given{c1}$ and $z$ free, $y = \given{c2}$. With $z = 0$, what is $x$?

::: misses
- [any] $x = c_1 - 2y$.
:::
:::
:::
