Skip to main content
โšก Calmops

Matrix Multiplication as Linear Transformation: An Intuitive Guide

Introduction

When most people first encounter matrices, they see a grid of numbers with confusing multiplication rules. But there’s a much more powerful way to think about matrices: every matrix represents a linear transformation of space.

This perspective โ€” championed by the 3Blue1Brown Essence of Linear Algebra series and the LAFF course โ€” makes matrix operations intuitive and reveals why linear algebra is so fundamental to graphics, machine learning, physics, and engineering.

What is a Linear Transformation?

A transformation is linear if it satisfies two properties:

1. Additivity:

$$L(x + y) = L(x) + L(y)$$

2. Scaling (Homogeneity):

$$L(\alpha x) = \alpha L(x)$$

Combined: $L(\alpha u + \beta v) = \alpha L(u) + \beta L(v)$

Geometrically, a linear transformation:

  • Keeps the origin fixed
  • Keeps lines straight (no curving)
  • Keeps grid lines parallel and evenly spaced

Rotations, reflections, scaling, and shearing are all linear transformations. Translations (shifting the origin) are not linear.

Basis Vectors: The Key Insight

In 2D space, every vector can be written as a combination of the basis vectors รฎ (1, 0) and ฤต (0, 1):

$$\begin{pmatrix} x \\ y \end{pmatrix} = x \cdot \hat{i} + y \cdot \hat{j} = x \begin{pmatrix} 1 \\ 0 \end{pmatrix} + y \begin{pmatrix} 0 \\ 1 \end{pmatrix}$$

Because of linearity, if you know where a transformation sends รฎ and ฤต, you know where it sends every vector:

$$L\begin{pmatrix} x \\ y \end{pmatrix} = x \cdot L(\hat{i}) + y \cdot L(\hat{j})$$

This is the entire idea behind matrices. A matrix is just a record of where the basis vectors land after a transformation.

Reading a Matrix as a Transformation

A 2ร—2 matrix:

$$M = \begin{pmatrix} a & b \\ c & d \end{pmatrix}$$
  • First column $(a, c)$: where รฎ = (1, 0) lands
  • Second column $(b, d)$: where ฤต = (0, 1) lands

Example: 90ยฐ counterclockwise rotation

After rotating 90ยฐ:

  • รฎ = (1, 0) โ†’ (0, 1)
  • ฤต = (0, 1) โ†’ (-1, 0)

So the rotation matrix is:

$$R_{90} = \begin{pmatrix} 0 & -1 \\ 1 & 0 \end{pmatrix}$$

Let’s verify with a vector (3, 2):

$$R_{90} \begin{pmatrix} 3 \\ 2 \end{pmatrix} = \begin{pmatrix} 0 \cdot 3 + (-1) \cdot 2 \\ 1 \cdot 3 + 0 \cdot 2 \end{pmatrix} = \begin{pmatrix} -2 \\ 3 \end{pmatrix}$$

(3, 2) rotated 90ยฐ counterclockwise is (-2, 3). โœ“

Common 2D Transformations

import numpy as np

# Rotation by angle ฮธ
def rotation_matrix(theta):
    c, s = np.cos(theta), np.sin(theta)
    return np.array([[c, -s],
                     [s,  c]])

# Scaling
def scale_matrix(sx, sy):
    return np.array([[sx, 0],
                     [0, sy]])

# Reflection across x-axis
reflect_x = np.array([[1,  0],
                       [0, -1]])

# Reflection across y-axis
reflect_y = np.array([[-1, 0],
                       [0,  1]])

# Horizontal shear
def shear_matrix(k):
    return np.array([[1, k],
                     [0, 1]])

# Apply rotation of 45ยฐ to a vector
v = np.array([1, 0])
R = rotation_matrix(np.pi / 4)
print(R @ v)  # => [0.707, 0.707]

Matrix Multiplication = Composing Transformations

When you multiply two matrices, you’re composing two transformations โ€” applying one after the other:

$$AB \cdot v = A(B \cdot v)$$

Note: The rightmost matrix is applied first. $AB$ means “first apply B, then apply A.”

# Rotate 90ยฐ, then scale by 2
R = rotation_matrix(np.pi / 2)
S = scale_matrix(2, 2)

# Compose: scale after rotation
RS = S @ R

v = np.array([1, 0])
print(R @ v)   # => [0, 1]   (rotated)
print(RS @ v)  # => [0, 2]   (rotated then scaled)

Why order matters:

# Rotate then shear โ‰  shear then rotate
R = rotation_matrix(np.pi / 4)
H = shear_matrix(1)

v = np.array([1, 0])
print((R @ H) @ v)  # rotate then shear
print((H @ R) @ v)  # shear then rotate
# Different results!

The Determinant: How Much Space is Scaled

The determinant of a transformation matrix tells you how much the transformation scales areas (2D) or volumes (3D):

$$\det\begin{pmatrix} a & b \\ c & d \end{pmatrix} = ad - bc$$
  • det = 2: areas are doubled
  • det = 0.5: areas are halved
  • det = 0: the transformation squishes space into a lower dimension (not invertible)
  • det < 0: the transformation flips orientation (like a reflection)
# Rotation preserves area โ€” det = 1
R = rotation_matrix(np.pi / 3)
print(np.linalg.det(R))  # => 1.0

# Scaling by 2 in both dimensions โ€” det = 4
S = scale_matrix(2, 2)
print(np.linalg.det(S))  # => 4.0

# Projection onto x-axis โ€” det = 0 (squishes to a line)
P = np.array([[1, 0], [0, 0]])
print(np.linalg.det(P))  # => 0.0

Eigenvectors: Vectors That Don’t Rotate

An eigenvector of a transformation is a vector that only gets scaled (not rotated) by the transformation:

$$Av = \lambda v$$

where ฮป (lambda) is the eigenvalue โ€” the scaling factor.

# Find eigenvectors and eigenvalues
A = np.array([[3, 1],
              [0, 2]])

eigenvalues, eigenvectors = np.linalg.eig(A)
print("Eigenvalues:", eigenvalues)   # => [3. 2.]
print("Eigenvectors:\n", eigenvectors)

# Verify: A @ v = ฮป * v
v = eigenvectors[:, 0]  # first eigenvector
lam = eigenvalues[0]    # first eigenvalue
print(np.allclose(A @ v, lam * v))  # => True

Eigenvectors are fundamental to PCA, Google’s PageRank, quantum mechanics, and many other applications.

3D Transformations

The same principles extend to 3D:

# 3D rotation around z-axis
def rotation_z(theta):
    c, s = np.cos(theta), np.sin(theta)
    return np.array([[c, -s, 0],
                     [s,  c, 0],
                     [0,  0, 1]])

# 3D scaling
def scale_3d(sx, sy, sz):
    return np.diag([sx, sy, sz])

# Apply to a 3D vector
v = np.array([1, 0, 0])
R = rotation_z(np.pi / 2)
print(R @ v)  # => [0, 1, 0]

Interactive Visualization

The Timmy tool from UT Austin’s LAFF course lets you manipulate linear transformations visually and see how they affect the grid in real time โ€” highly recommended for building intuition.

For 3D, 3Blue1Brown’s Essence of Linear Algebra series provides the best visual explanations available.

Key Takeaways

  • A matrix is a record of where basis vectors land after a transformation
  • Matrix-vector multiplication applies the transformation to a vector
  • Matrix-matrix multiplication composes two transformations
  • The determinant measures how much the transformation scales area/volume
  • Eigenvectors are the “axes” of a transformation โ€” they only get scaled, not rotated

Resources

Comments