Chapter 5: Subspaces, basis and rank

Previous: LA 04 Solving Linear Systems | LA 00 Course Map | Next: LA 06 Orthogonality and Least Squares

The big idea

Every matrix has a set of outputs it can reach (the column space) and a set of inputs it destroys (the null space). One number, the rank, tells you the size of both. Together they explain everything about when can be solved and how many solutions it has.

In this chapter you will learn to
  1. Decide whether a set of vectors is a subspace.
  2. Find a basis and the dimension of a subspace.
  3. Compute the column space, null space and rank of a matrix.
  4. Use rank-nullity to count dimensions without solving anything.
  5. Describe all four fundamental subspaces and how they fit together.
Before you start

You need span and linear independence (LA 01 Vectors and Linear Combinations) and elimination with free variables (LA 04 Solving Linear Systems).


5.1 Subspaces

Motivation

In chapter 1, spans always came out as lines, planes, or bigger flat pieces through the origin. In chapter 4, the solutions of had the same kind of shape. We want a name for this kind of set, and a quick test for it.

The definition

Definition: subspace

A set of vectors in is a subspace if

  1. it contains the zero vector,
  2. adding any two vectors in gives a vector in (closed under addition),
  3. scaling any vector in gives a vector in (closed under scaling).

In words: you can never leave by adding or scaling. It is a self-contained world for linear combinations.

What subspaces look like

In there are exactly four kinds:

DimensionSubspace
0just the origin
1a line through the origin
2a plane through the origin
3all of

Not subspaces:

  • A line that misses the origin, such as . It fails rule 1.
  • The first quadrant . Scaling by leaves it. Fails rule 3.
  • Two crossing lines, such as the -axis together with the -axis. is on neither. Fails rule 2.
  • A circle. Fails all three.

How to test

To show a set is a subspace, check all three rules for arbitrary members. To show it is not, give one counterexample.

Worked example 5.1. Is a subspace?

  1. satisfies . ✓
  2. Take in , so and . Adding the equations: , so . ✓
  3. Multiplying by gives , so . ✓

Yes, it is a subspace: a plane through the origin.

Worked example 5.2. Is a subspace? No: gives . It is a plane, but shifted off the origin.

The shortcut

Any solution set of a homogeneous system is a subspace. Any span is a subspace. Those two facts cover almost every subspace you will meet.


5.2 Basis and dimension

Basis

Definition: basis

A basis of a subspace is a set of vectors that

  1. spans (enough vectors to build everything), and
  2. is linearly independent (no wasted vectors).

A basis is a minimal complete set of building blocks.

Uniqueness of coordinates. If is a basis, every vector in can be written as in exactly one way.

Why exactly one? Spanning guarantees at least one way. If there were two, , then , and independence forces every . So the two ways are the same.

Dimension

A subspace has many different bases, but they always contain the same number of vectors. That number is the dimension.

SubspaceA basisDimension
2
(another basis)2
line through 1
plane 2
none (empty basis)0

Why is the number always the same? The key fact (proved in most textbooks; we state it) is:

Counting fact

In a space of dimension :

  • any set of more than vectors is dependent,
  • any set of fewer than vectors cannot span.

So a basis, being both independent and spanning, has exactly vectors.

A useful consequence: in a space of dimension , any independent vectors automatically span, and any spanning vectors are automatically independent. You only need to check one condition.

Finding a basis of a plane

Worked example 5.3. Find a basis of .

Solve for one variable: . The free choices are and :

So and span . They are independent (neither is a multiple of the other). Basis found; dimension 2.


5.3 The column space: what the matrix can reach

Definition: column space

The column space of an matrix is the span of its columns. Equivalently, it is the set of all outputs . It is a subspace of (the output space).

The solvability rule

has a solution if and only if is in the column space of .

This is just the column view from chapter 3 restated: is a combination of the columns, so must be one.

Finding a basis for the column space

  1. Row reduce to echelon form.
  2. Note which columns contain pivots.
  3. The corresponding columns of the original form a basis of .
Use the original columns

Row operations change the column space (they mix the rows, which changes every column). They do not change which columns are independent. So elimination tells you which columns to take, but you must take them from itself.

Worked example 5.4.

(Steps: , , then .)

Pivots are in columns 1 and 3. So a basis of is

The column space is a plane in . The other columns are combinations of these: column 2 is twice column 1, and column 4 is column 1 plus twice column 3.


5.4 The null space: what the matrix destroys

Definition: null space

The null space is the set of all with . It is a subspace of (the input space).

If , different inputs always give different outputs, so no information is lost. If is bigger, whole directions of input are flattened to zero and can never be recovered from the output.

Finding a basis for the null space

  1. Row reduce (the right side stays 0, so you need not write it).
  2. Identify the free variables.
  3. Set one free variable to 1 and the others to 0; solve for the pivot variables. Repeat for each free variable.
  4. The vectors you get form a basis of .

Worked example 5.5. Continue with from example 5.4. The echelon form gives

Free variables: and (no pivots in columns 2 and 4).

  • , : then and . Vector .
  • , : then and . Vector .

Check the first: . ✓

Each null space vector is a recipe for zero using the columns, which is a dependency among the columns. The null space records every way the columns are redundant.


5.5 Rank and the rank-nullity theorem

Definition: rank

The rank of is the dimension of its column space: the number of independent columns. It equals the number of pivots found by elimination.

In example 5.4 the rank is 2.

Row rank equals column rank

A remarkable fact: the number of independent rows always equals the number of independent columns. So

Why (sketch): elimination does not change the row space, and the nonzero rows of the echelon form are independent, so the number of independent rows is the number of pivots. The number of independent columns is also the number of pivots (section 5.3). Both equal the pivot count.

Rank-nullity

Rank-nullity theorem

For an matrix:

Why it is true. Every column is either a pivot column or a free column. Pivot columns count the rank. Each free column contributes one basis vector of the null space. Together they account for all columns.

Meaning. Each of the input dimensions is either kept (it contributes to the output) or destroyed (it lands in the null space). Nothing else can happen. It is a conservation law for dimensions.

Check with example 5.4: rank 2, nullity 2, columns 4. ✓.

Worked example 5.6 (using it without solving). A matrix has rank 3. Then:

  • the column space is a 3-dimensional subspace of , so most in are not reachable;
  • the null space has dimension , so every solvable system has a 5-parameter family of solutions.

5.6 The four fundamental subspaces

Every matrix comes with four subspaces:

SubspaceLives inDimensionMeaning
column space (outputs)outputs you can reach
null space (inputs)inputs sent to zero
row space (inputs)input directions that matter
left null space (outputs)output directions never reached

How they fit together

Orthogonality of the subspaces
  • The row space is perpendicular to the null space.
  • The column space is perpendicular to the left null space.

Why the first. means every row of has zero dot product with . So is perpendicular to every row, and therefore (chapter 2, exercise C3) to every combination of rows: the whole row space.

So the input space splits into two perpendicular pieces, row space and null space, whose dimensions add to . The output space splits into column space and left null space, whose dimensions add to .

The complete picture of what a matrix does

Take any input . Split it into a row-space part and a null-space part . Then

So:

  1. The null-space part is thrown away.
  2. The row-space part is mapped one-to-one onto the column space.
  3. The left null space is never reached.

Every matrix, of any shape, works this way. Chapter 10 (SVD) gives perfect perpendicular bases for all four pieces.


5.7 What rank tells you about

Shape and rankNameSolutions of
square, invertibleexactly one, for every
tall, full column rankzero or one
wide, full row rankinfinitely many, for every
and rank deficientzero or infinitely many

Why each row holds.

  • means the column space is all of : every is reachable.
  • means the null space is : at most one solution.
  • Combine the two conditions as needed.

Two common real cases.

  • Tall (more equations than unknowns): data fitting. 100 measurements, 3 parameters. Usually no exact solution, which is where chapter 6 (least squares) comes in.
  • Wide (more unknowns than equations): a redundant robot arm. A 7-joint arm controlling a 6-D hand pose has a 1-dimensional null space: joint motions that move the elbow without moving the hand.

Summary

ConceptHow to computeDimension
column spacepivot columns of the original
null spaceone vector per free variable
row spacenonzero rows of the echelon form
ranknumber of pivots

Three facts to remember:

  1. is solvable exactly when is in the column space.
  2. Rank + nullity = number of columns.
  3. Row space null space: a matrix keeps the row-space part of and throws away the rest.

Exercises

Part A: warm-up

A1. Which are subspaces of ? (a) (b) (c) (d)

A2. Find a basis and the dimension of .

A3. Find the rank of and a basis of its null space.

A4. A matrix has rank 4. Give the dimensions of all four fundamental subspaces.

Part B: core

B1. For

find a basis of the column space, a basis of the null space, and the rank. Verify rank-nullity.

B2. Is in the column space of the in B1? Is ?

B3. Find a basis of the row space of the in B1, and check that each basis vector is perpendicular to each null space basis vector you found.

B4. Find a matrix whose null space is spanned by .

B5. A 7-joint arm has a Jacobian of rank 6. What is the dimension of the set of joint velocities with ? Interpret.

B6. Show that , , form a basis of , and find the coordinates of in this basis.

Part C: explain and prove

C1. Prove that the null space of any matrix is a subspace.

C2. Prove that if is with , then has a nonzero solution.

C3. Explain why row operations do not change the null space but can change the column space. Give a example where the column space changes.

C4. Prove that if the columns of are independent, then is invertible. (Hint: suppose , dot both sides with .)

Part D: practise with code

D1. Use np.linalg.matrix_rank to check your ranks in A3 and B1.

D2. scipy.linalg.null_space(A) returns an orthonormal basis of the null space. Compare it with your hand-computed basis for B1. They will look different. Explain why both are correct (hint: check that each SciPy vector is a combination of yours).

D3. sympy.Matrix(A).rref() returns the reduced row echelon form and the pivot columns. Use it on B1 and on example 5.4.

D4. Generate a matrix A = np.random.randn(5, 3), then make a new matrix whose fourth column is A[:,0] + 2*A[:,1]. What is the rank before and after? What is a vector in the null space of the new matrix?


Where this is used

  • Robot Jacobians. A drop in rank is a singularity: the hand loses the ability to move in some direction (02 Geometry and Kinematics). The null space of a redundant arm’s Jacobian is used for secondary goals like avoiding joint limits.
  • Data. If a feature is a combination of others, the data matrix is rank deficient and a regression has no unique answer.
  • Low-rank structure. Many real datasets are close to low rank, which is what makes compression and PCA work (LA 10 Singular Value Decomposition).

Next: LA 06 Orthogonality and Least Squares: what to do when is not in the column space.