AnyLearn
All lessons
Mathintermediate

Matrices as Linear Transformations

A matrix doesn't just hold numbers — it reshapes space. Master the geometric view of matrix-vector multiplication, the four fundamental subspaces, rank, the determinant as a volume-scaling factor, and invertibility — all grounded in NumPy.

Not signed in — your progress and quiz score won't be saved.
Lesson progress1 / 10

A matrix is a machine that transforms space

Every m×nm\times n matrix AA defines a function T:RnRmT:\mathbb{R}^n\to\mathbb{R}^m by

T(x)=Ax.T(\mathbf{x}) = A\mathbf{x}.

This is a linear map: T(u+v)=T(u)+T(v)T(\mathbf{u}+\mathbf{v})=T(\mathbf{u})+T(\mathbf{v}) and T(cu)=cT(u)T(c\mathbf{u})=cT(\mathbf{u}). Linearity is not an assumption — it falls straight out of matrix multiplication.

Geometrically, AA takes every vector in Rn\mathbb{R}^n and lands it somewhere in Rm\mathbb{R}^m. The entire input space gets transformed at once:

  • A 2×22\times 2 matrix rotates, reflects, stretches, or shears the plane.
  • A 3×23\times 2 matrix embeds a plane into 3-D space.
  • A 1×31\times 3 matrix collapses 3-D space onto a line.

The columns of AA are the key: Ax=x1a1+x2a2++xnanA\mathbf{x} = x_1\mathbf{a}_1 + x_2\mathbf{a}_2 + \cdots + x_n\mathbf{a}_n — just a linear combination of the columns of AA, weighted by the entries of x\mathbf{x}.

Full lesson text

All 10 steps on one page — for reading, reference, and search.

Show

1. A matrix is a machine that transforms space

Every m×nm\times n matrix AA defines a function T:RnRmT:\mathbb{R}^n\to\mathbb{R}^m by

T(x)=Ax.T(\mathbf{x}) = A\mathbf{x}.

This is a linear map: T(u+v)=T(u)+T(v)T(\mathbf{u}+\mathbf{v})=T(\mathbf{u})+T(\mathbf{v}) and T(cu)=cT(u)T(c\mathbf{u})=cT(\mathbf{u}). Linearity is not an assumption — it falls straight out of matrix multiplication.

Geometrically, AA takes every vector in Rn\mathbb{R}^n and lands it somewhere in Rm\mathbb{R}^m. The entire input space gets transformed at once:

  • A 2×22\times 2 matrix rotates, reflects, stretches, or shears the plane.
  • A 3×23\times 2 matrix embeds a plane into 3-D space.
  • A 1×31\times 3 matrix collapses 3-D space onto a line.

The columns of AA are the key: Ax=x1a1+x2a2++xnanA\mathbf{x} = x_1\mathbf{a}_1 + x_2\mathbf{a}_2 + \cdots + x_n\mathbf{a}_n — just a linear combination of the columns of AA, weighted by the entries of x\mathbf{x}.

2. Matrix multiplication = composition of transformations

If AA transforms RnRm\mathbb{R}^n\to\mathbb{R}^m and BB transforms RpRn\mathbb{R}^p\to\mathbb{R}^n, then applying BB first then AA gives a single transformation RpRm\mathbb{R}^p\to\mathbb{R}^m encoded by the product ABAB:

(AB)x=A(Bx).(AB)\mathbf{x} = A(B\mathbf{x}).

This is why matrix multiplication is defined the way it is — it isn't an arbitrary rule, it's composition of functions.

Concrete example. Let RR be a 90° counter-clockwise rotation: R=[0110]R = \begin{bmatrix}0&-1\\1&0\end{bmatrix} and SS a uniform scale by 22: S=2IS=2I. Then RSRS first scales then rotates, but in 2-D it happens that RS=SRRS = SR — scaling and rotation commute. In general ABBAAB\ne BA: composition of linear maps is not commutative. Order matters.

3. The column space and null space

Two subspaces defined by A:RnRmA:\mathbb{R}^n\to\mathbb{R}^m reveal everything about its behavior.

Column space C(A)\mathcal{C}(A) — the set of all outputs: C(A)={Ax:xRn}=span(a1,,an)Rm.\mathcal{C}(A) = \{A\mathbf{x} : \mathbf{x}\in\mathbb{R}^n\} = \operatorname{span}(\mathbf{a}_1,\dots,\mathbf{a}_n)\subseteq\mathbb{R}^m. Ax=bA\mathbf{x}=\mathbf{b} is solvable iff bC(A)\mathbf{b}\in\mathcal{C}(A).

Null space N(A)\mathcal{N}(A) — the set of inputs that map to zero: N(A)={xRn:Ax=0}Rn.\mathcal{N}(A) = \{\mathbf{x}\in\mathbb{R}^n : A\mathbf{x}=\mathbf{0}\}\subseteq\mathbb{R}^n. N(A)\mathcal{N}(A) measures redundancy in AA's columns: a nonzero null vector means two different inputs produce the same output (the map is not injective). If x^\hat{\mathbf{x}} is any particular solution to Ax=bA\mathbf{x}=\mathbf{b}, then the full solution set is the affine subspace x^+N(A)\hat{\mathbf{x}}+\mathcal{N}(A).

4. All four fundamental subspaces

Gilbert Strang's four fundamental subspaces of an m×nm\times n matrix AA:

SubspaceLives inDefinition
Column space C(A)\mathcal{C}(A)Rm\mathbb{R}^mSpan of columns
Null space N(A)\mathcal{N}(A)Rn\mathbb{R}^nSolutions to Ax=0A\mathbf{x}=\mathbf{0}
Row space C(A)\mathcal{C}(A^\top)Rn\mathbb{R}^nSpan of rows
Left null space N(A)\mathcal{N}(A^\top)Rm\mathbb{R}^mSolutions to Ay=0A^\top\mathbf{y}=\mathbf{0}

The key orthogonality relations: C(A)N(A)\mathcal{C}(A^\top)\perp\mathcal{N}(A) (they partition Rn\mathbb{R}^n) and C(A)N(A)\mathcal{C}(A)\perp\mathcal{N}(A^\top) (they partition Rm\mathbb{R}^m). Every input vector splits into a row-space component (which AA maps faithfully) and a null-space component (which AA kills). These four spaces are the complete anatomy of what any matrix does.

5. Rank and the rank-nullity theorem

The rank of AA is the dimension of its column space:

rank(A)=dimC(A)=dimC(A).\operatorname{rank}(A) = \dim\mathcal{C}(A) = \dim\mathcal{C}(A^\top).

(Row rank equals column rank — always, for any matrix. That's non-obvious but true.)

The rank-nullity theorem is linear algebra's conservation law:

rank(A)+nullity(A)=n\operatorname{rank}(A) + \operatorname{nullity}(A) = n

where nullity(A)=dimN(A)\operatorname{nullity}(A) = \dim\mathcal{N}(A) and nn is the number of columns. Inputs are split between the row space (dimension = rank, faithfully mapped) and the null space (dimension = nullity, sent to zero). The rank tells you how much of Rm\mathbb{R}^m you can reach; the nullity tells you how much of Rn\mathbb{R}^n you lose.

A square n×nn\times n matrix is full rank (rank=n\operatorname{rank}=n) iff its null space is {0}\{\mathbf{0}\} — the only way to invert a map is to lose nothing.

6. The determinant: volume scaling

For a square n×nn\times n matrix AA, the determinant det(A)\det(A) is the signed factor by which AA scales nn-dimensional volumes. Feed in a unit cube; out comes a parallelepiped with volume det(A)|\det(A)|.

For 2×22\times 2: det[abcd]=adbc\det\begin{bmatrix}a&b\\c&d\end{bmatrix} = ad-bc — the signed area of the parallelogram formed by the columns.

Key facts:

  • det(A)=0\det(A)=0 iff AA collapses space to a lower dimension (rank-deficient, singular).
  • det(AB)=det(A)det(B)\det(AB)=\det(A)\det(B) — determinants compose under multiplication.
  • det(A1)=1/det(A)\det(A^{-1})=1/\det(A) — inverting a map inverts the scaling factor.
  • Sign encodes orientation: det>0\det>0 preserves handedness; det<0\det<0 flips it (like a mirror reflection).

Do not use the determinant to check invertibility for floating-point matrices — a determinant of 101510^{-15} isn't zero, but it indicates a nearly-singular matrix that behaves poorly numerically. Use np.linalg.matrix_rank or condition numbers instead.

7. The four fundamental subspaces at a glance

How an m×nm\times n matrix AA partitions its domain Rn\mathbb{R}^n and codomain Rm\mathbb{R}^m:

flowchart LR
  Rn["Input space R^n"]
  RS["Row space C(A^T) -- dim = rank"]
  NS["Null space N(A) -- dim = nullity"]
  Rm["Output space R^m"]
  CS["Column space C(A) -- dim = rank"]
  LN["Left null space N(A^T) -- dim = m - rank"]
  Rn --> RS
  Rn --> NS
  RS --> CS
  NS --> Z["Zero vector"]
  CS --> Rm
  LN --> Rm

8. Invertibility: when can we reverse the transformation?

A square n×nn\times n matrix AA is invertible (nonsingular) iff any of the following equivalent conditions hold:

  • det(A)0\det(A)\ne 0
  • rank(A)=n\operatorname{rank}(A)=n (full rank)
  • N(A)={0}\mathcal{N}(A)=\{\mathbf{0}\} (trivial null space)
  • The columns of AA form a basis of Rn\mathbb{R}^n
  • Ax=bA\mathbf{x}=\mathbf{b} has a unique solution for every b\mathbf{b}

All five conditions are the same condition, five disguises. The inverse satisfies AA1=A1A=IAA^{-1}=A^{-1}A=I and (AB)1=B1A1(AB)^{-1}=B^{-1}A^{-1} — inversion reverses composition.

For rectangular m×nm\times n matrices, exact inverses don't exist, but left inverses (n>mn>m) and right inverses (m>nm>n) do under full-rank conditions. The pseudoinverse (Lesson 4) handles the general case.

9. NumPy: exploring transformations and rank

Put it all together in code:

import numpy as np

A = np.array([[1, 2, 3],
              [4, 5, 6],
              [7, 8, 9]], dtype=float)

print("rank =", np.linalg.matrix_rank(A))   # 2 — not full rank!
print("det  =", np.linalg.det(A))            # ~0 (singular)

# Find the null space vector (Ax = 0)
_, _, Vt = np.linalg.svd(A)
null_vec = Vt[-1]                            # last right singular vector
print("A @ null_vec =", np.round(A @ null_vec, 10))  # [0, 0, 0]

# Invertible matrix
B = np.array([[1, 0, 2], [0, 1, 0], [3, 0, 1]], dtype=float)
print("rank(B) =", np.linalg.matrix_rank(B))  # 3
print("B_inv @ B =", np.round(np.linalg.inv(B) @ B, 10))  # Identity

The SVD approach to the null space is not an accident — it's the numerically correct way. The last right singular vector of AA corresponds to its smallest singular value, pointing maximally "into" the null space.

10. Geometric summary: what every matrix does

Any matrix AA performs exactly four things to space, visible in its four fundamental subspaces:

  1. Maps faithfully the row-space component of each input — stretching along singular directions (singular values, revealed in Lesson 4).
  2. Kills the null-space component — irreversibly loses information.
  3. Reaches exactly the column space in the output — not all of Rm\mathbb{R}^m if rank <m< m.
  4. Misses the left null space entirely — no input ever lands there.

Full rank (m=n=rankm=n=\operatorname{rank}) means steps 2 and 4 are empty: nothing is lost, everything is reached, the map is invertible. Drop rank by one and you collapse an entire direction to zero — the determinant records this as a zero.

Next lesson: what if AA has special vectors that only get scaled (not rotated) by the transformation? Those are eigenvectors, and they unlock the deepest structure inside a matrix.

Check your understanding

The lesson ends with a 5-question quiz. Take it in the player above to see your score.

  1. For a $5\times 7$ matrix $A$ with rank 4, what is the dimension of its null space?
    • 4, since the rank is 4.
    • 1, since $5-4=1$.
    • 3, since $7-4=3$ by the rank-nullity theorem.
    • 2, since $\min(5,7)-4=1$... wait, it's ambiguous.
  2. The system $A\mathbf{x}=\mathbf{b}$ is solvable if and only if:
    • $\mathbf{b}$ is orthogonal to the row space of $A$.
    • $\mathbf{b}$ lies in the column space of $A$.
    • $\mathbf{b}$ lies in the null space of $A$.
    • $A$ is a square matrix.
  3. What does $\det(A)=0$ mean geometrically for a square matrix $A$?
    • $A$ scales every vector by zero.
    • $A$ maps space to a lower-dimensional subspace — the volume of any region collapses to zero.
    • $A$ is the identity matrix scaled by zero.
    • $A$ is orthogonal and preserves lengths.
  4. Matrix multiplication $AB$ represents:
    • The element-wise product of $A$ and $B$.
    • The composition of linear maps: first apply $B$, then $A$.
    • The composition of linear maps: first apply $A$, then $B$.
    • The outer product of the row vectors of $A$ with the columns of $B$.
  5. Which statement about the row space and null space of $A$ is always true?
    • The row space and null space together span all of $\mathbb{R}^m$.
    • The row space and null space of $A$ are orthogonal complements in $\mathbb{R}^n$.
    • The row space equals the null space when $A$ is symmetric.
    • The null space is a subspace of the row space.

Related lessons