Rank, nullity, and the four fundamental subspaces
Prove the rank–nullity theorem and use the four fundamental subspaces to decide when Ax=b is solvable and how many solutions there are.
The matrix of a linear map carves out four subspaces: two inside the domain, two inside the codomain. Their dimensions are linked by a single equation, and that equation tells you everything about the solvability of .
The four fundamental subspaces
For an matrix :
| Subspace | Space | Definition |
|---|---|---|
| Column space | ||
| Null space | ||
| Row space | ||
| Left null space |
The column space is where can land; the null space is what collapses to zero. The rank is , the number of linearly independent columns (equivalently, independent rows: row rank equals column rank, a nontrivial fact[1]). The nullity is .
Rank–nullity theorem
Theorem. For any [2],
Proof. Let and ; pick a basis for . Extend it to a basis of by adding .
Step 1: spans . Any with satisfies (the are annihilated). So every column-space vector is a combination of the .
Step 2: is independent. Suppose , i.e. . Then , so for some . But is a basis of , so all coefficients are zero. Hence all .
Steps 1 and 2 together say is a basis of , confirming . The original basis of had elements.
Solvability and solution structure
The system is consistent if and only if .
When it is consistent, the solution set is a coset of the null space: pick any particular solution (i.e. ), then every solution has the form
Proof. If and , then , so . Conversely, for any .
In particular: if (the null space is just ), the solution is unique when it exists. If nullity is positive, there are infinitely many.
Orthogonality of the four spaces
Row space and null space are orthogonal complements in : every row- space vector is orthogonal to every null-space vector. The cleanest route to this is: if and is any row of , then by definition. So the null space is perpendicular to every row, hence to the entire row space. By dimension count (row space has dimension , null space has dimension , and they are orthogonal), they are orthogonal complements. The same argument gives col space left null space in .
Check it on arrays
import numpy as np
A = np.array([
[1.0, 2.0, 3.0],
[2.0, 4.0, 6.0], # row 2 = 2 * row 1
[0.0, 1.0, 1.0],
], dtype=float)
r = np.linalg.matrix_rank(A)
n = A.shape[1]
print(f"rank={r}, nullity={n - r}, rank+nullity={n}") # 2, 1, 3
# Null space via SVD (last right singular vectors for near-zero singular values):
_, s, Vt = np.linalg.svd(A)
print("singular values:", np.round(s, 6)) # one near zero
null_vec = Vt[-1] # approximate null vector
print("A @ null_vec:", np.round(A @ null_vec, 10)) # ~zero
# Verify row space ⊥ null space:
# Row 0 should be orthogonal to null_vec
print("row0 . null_vec:", np.round(A[0] @ null_vec, 10)) # ~0The near-zero singular value flags the one-dimensional null space; the null vector is numerically orthogonal to every row.
Exercises
Exercise 1. Let . Find the rank and nullity, and verify the rank-nullity theorem.
Solution
Step 1. Row 2 is row 1, so the two rows are linearly dependent and there is exactly one independent row. Hence .
Step 2. The matrix has columns, so rank-nullity gives .
Step 3. Check directly: reduces to the single equation (row 2 is redundant). One linear constraint on three unknowns leaves a -dimensional solution space, matching nullity . The sum confirms the theorem.
Exercise 2. A matrix is with . For how many right-hand sides is consistent, and when consistent, how many solutions does it have?
Solution
Step 1. Consistency. The column space lives in and has dimension , so . Every is in the column space, so is consistent for all .
Step 2. Count solutions. By rank-nullity, , which is positive.
Step 3. When consistent, the solution set is the coset from the lesson. A null space of dimension contains infinitely many vectors, so there are infinitely many solutions for every .
Exercise 3 (code). Build a matrix whose 4th column is a fixed combination of the first three (so rank , nullity ). Confirm the rank and nullity numerically, recover a null vector from the SVD, and verify it is orthogonal to every row of .
Solution
A column dependence forces nullity ; with three independent columns the rank is exactly . The null space is the orthogonal complement of the row space, so the null vector must be orthogonal to each row.
import numpy as np
rng = np.random.default_rng(0)
A = rng.normal(size=(5, 4))
A[:, 3] = 2.0 * A[:, 0] - A[:, 1] # 4th column depends on cols 0 and 1
r = np.linalg.matrix_rank(A)
n = A.shape[1]
assert r == 3 and n - r == 1 # rank 3, nullity 1
# Null vector: right singular vector of the smallest singular value.
_, s, Vt = np.linalg.svd(A)
null_vec = Vt[-1]
assert np.allclose(A @ null_vec, 0, atol=1e-12)
# Row space is orthogonal to the null space: every row . null_vec == 0.
for row in A:
assert abs(row @ null_vec) < 1e-10
print("rank:", r, "nullity:", n - r, "max |row . null|:",
np.max(np.abs(A @ null_vec)))The smallest singular value is numerically zero, flagging the one-dimensional null space, and states exactly that is orthogonal to every row of , the row-space/null-space orthogonality from the lesson.
The next lesson builds a ruler for measuring the length of vectors sitting in these spaces.
References
- [1]Strang, G. (2016). Introduction to Linear Algebra (5th ed.). Wellesley-Cambridge Press. The four fundamental subspaces and the equality of row and column rank.↩
- [2]Axler, S. (2015). Linear Algebra Done Right (3rd ed.), ch. 3. Springer. The rank-nullity theorem (fundamental theorem of linear maps) (doi:10.1007/978-3-319-11080-6).↩