Matrix Multiplication

Composing transformations through matrices

Matrices as Transformations

Before we can understand matrix multiplication, we need to see what a single matrix does. A 2×2 matrix is not just a grid of numbers—it is a complete description of how to transform space.

When we multiply a matrix by a vector, we are asking: where does this vector land after the transformation? The answer comes from a beautifully simple rule: the columns of the matrix tell you where the basis vectors i^\hat{i} and j^\hat{j} end up.

Interactive: Matrix-Vector Multiplication

v=(1.0,1.0)\vec{v} = (1.0, 1.0)Av=(1.0,2.0)A\vec{v} = (1.0, 2.0)

Drag the white vector to see how the matrix transforms it

The formula for transforming a vector is:

[abcd][xy]=x[ac]+y[bd]\begin{bmatrix} a & b \\ c & d \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = x \begin{bmatrix} a \\ c \end{bmatrix} + y \begin{bmatrix} b \\ d \end{bmatrix}

Read this carefully: we take xx copies of the first column and yy copies of the second column, then add them together. The columns of the matrix are literally the transformed basis vectors.

Reading a Matrix

This insight changes how we should think about matrices. Instead of memorizing a formula, we can read what a matrix does directly from its columns.

The first column tells us where i^=(1,0)\hat{i} = (1, 0) lands. The second column tells us where j^=(0,1)\hat{j} = (0, 1) lands. Everything else follows from linearity.

Interactive: Build Your Own Transformation

1.0
0.0
0.0
1.0
A=[1.00.00.01.0]A = \begin{bmatrix} 1.0 & 0.0 \\ 0.0 & 1.0 \end{bmatrix}

The columns of the matrix are where î and ĵ land after transformation

Try setting a=0,b=1,c=1,d=0a = 0, b = -1, c = 1, d = 0. You will see a 90° rotation. Set a=2,b=0,c=0,d=2a = 2, b = 0, c = 0, d = 2 for uniform scaling. The numbers directly encode the geometry.

Composition: One Transformation After Another

Now for the key insight that unlocks matrix multiplication. Suppose we have two transformations, each described by its own matrix. What if we want to apply one, then the other?

We could transform a vector by the first matrix, then take that result and transform it by the second matrix. But there is a better way: we can combine the two matrices into a single matrix that captures the entire composed transformation.

Interactive: Composing Two Transformations

0
Original vectors î and ĵ
A=[0.870.50.50.87]A = \begin{bmatrix} 0.87 & -0.5 \\ 0.5 & 0.87 \end{bmatrix}

Rotation

B=[1.5000.5]B = \begin{bmatrix} 1.5 & 0 \\ 0 & 0.5 \end{bmatrix}

Scaling

When we write BABA, we mean: first apply AA, then apply BB. The resulting matrix BABA is computed by asking where the basis vectors land after both transformations.

(BA)v=B(Av)(BA)\vec{v} = B(A\vec{v})

The product matrix BABA captures this composition. Its first column is where i^\hat{i} ends up after both transformations. Its second column is where j^\hat{j} ends up.

The Multiplication Formula

To compute the product, we transform each column of the second matrix by the first matrix:

[abcd][efgh]=[ae+bgaf+bhce+dgcf+dh]\begin{bmatrix} a & b \\ c & d \end{bmatrix} \begin{bmatrix} e & f \\ g & h \end{bmatrix} = \begin{bmatrix} ae + bg & af + bh \\ ce + dg & cf + dh \end{bmatrix}

Each column of the result comes from multiplying the left matrix by the corresponding column of the right matrix. This is not an arbitrary formula—it is the natural consequence of composing transformations.

Order Matters

Here is something crucial that catches many people off guard: matrix multiplication is not commutative. In general, ABBAAB \neq BA.

Think about it geometrically. Rotating then shearing gives a different result than shearing then rotating. The order of transformations matters, so the order of matrix multiplication must matter too.

Interactive: AB vs BA

A=[1101]A = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}

Shear

B=[0110]B = \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}

90° Rotation

AB=[1110]AB = \begin{bmatrix} 1 & -1 \\ 1 & 0 \end{bmatrix}

Notice how the results are completely different!

This is not a quirk of the notation—it reflects a deep truth about transformations in space. When you shear first, you are shearing the original coordinate system. When you rotate first, the shear operates on an already-rotated system. The outcomes are genuinely different.

The Identity Matrix

There is one special matrix that deserves attention: the identity matrix. It leaves every vector exactly where it is.

I=[1001]I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}

The identity matrix sends i^\hat{i} to (1,0)(1, 0) and j^\hat{j} to (0,1)(0, 1)—exactly where they started. For any matrix AA:

AI=IA=AAI = IA = A

Multiplying by the identity is like multiplying a number by 1. It is the do-nothing transformation, and it plays the role of the neutral element in matrix multiplication.

Interactive: From Identity to Transformation

1.0
[2.001.000.501.50]\begin{bmatrix} 2.00 & 1.00 \\ 0.50 & 1.50 \end{bmatrix}

Full transformation applied

Why This Matters

Matrix multiplication is the engine behind countless applications. In computer graphics, we chain transformations (translate, rotate, scale) into a single matrix. In machine learning, neural networks are essentially long compositions of linear transformations.

The geometric interpretation gives us intuition. The algebraic formulas give us computation. Together, they make matrices one of the most powerful tools in applied mathematics.

Key Takeaways

  • A matrix transforms space by moving the basis vectors to new positions
  • The columns of a matrix are where î and ĵ land after the transformation
  • Matrix multiplication composes transformations: BABA means first AA, then BB
  • Order matters: ABBAAB \neq BA in general
  • The identity matrix II leaves all vectors unchanged