Matrix Multiplication
The one operation that powers all of linear algebra — built from scratch, the way it finally clicks
§1Why Matrix Multiplication Is Strange — and Why That's Good
Let me be honest with you up front. When you first see how matrices multiply, your reaction will be: "who on earth invented this, and why so complicated?" You would add matrices entry-by-entry — sensible. You'd expect to multiply them entry-by-entry too. But that's not how it works, and there is a beautiful reason.
So forget memorising for a moment. We are going to build the operation from one tiny tool you already know — the dot product — and by the end it will feel inevitable. Stay with me.
§2The Building Block — the Dot Product
Everything in matrix multiplication is built from one simple move: take two equal-length lists of numbers, multiply them position-by-position, and add up the results.
The dot product of two lists of the same length, $(a_1, a_2, \dots, a_n)$ and $(b_1, b_2, \dots, b_n)$, is the single number $a_1 b_1 + a_2 b_2 + \cdots + a_n b_n.$
$(1, 2, 3) \cdot (4, 5, 6) = (1)(4) + (2)(5) + (3)(6) = 4 + 10 + 18 = 32.$
One row, one column, one number out. Hold onto this — it is the atom of everything that follows.
§3The Size Rule — When Can You Even Multiply?
Before multiplying, you must check the sizes line up. Unlike addition (which needs identical sizes), multiplication has its own rule — and it is the first thing to check every single time.
You can form the product $AB$ only when the number of columns of $A$ equals the number of rows of $B$. If $A$ is $m\times n$ and $B$ is $n\times p$, then $AB$ exists and has size $m\times p$.
The two inner numbers must match — they "touch and cancel." The two outer numbers give the size of the answer.
(a) $A$ is $2\times3$, $B$ is $3\times4$. Inner: $3 = 3$ ✓. Product $AB$ is $2\times4$.
(b) $A$ is $2\times3$, $B$ is $2\times3$. Inner: $3 \neq 2$. The product $AB$ does not exist.
(c) $A$ is $3\times1$ (a column), $B$ is $1\times3$ (a row). Inner: $1 = 1$ ✓. Product is $3\times3$ — a full matrix from a column times a row!
§4How To Actually Multiply — Row Meets Column
The entry in row $i$, column $j$ of $AB$ is the dot product of row $i$ of $A$ with column $j$ of $B$. In symbols, if $A=[a_{ik}]$ and $B=[b_{kj}]$, then $(AB)_{ij} = \sum_{k} a_{ik}\, b_{kj} = a_{i1}b_{1j} + a_{i2}b_{2j} + \cdots + a_{in}b_{nj}.$
Here is the rhythm to say in your head: "row $i$ of $A$, column $j$ of $B$ — multiply across, add up, drop it in slot $(i,j)$." Play with the demo below: choose any row of $A$ and any column of $B$, and watch exactly which dot product produces which entry.
This number lands in row 1, column 1 of the product AB. Every entry of AB is one row·column dot product.
§5Worked Examples — From Easy to Confident
Compute $AB$ for $A = \begin{bmatrix}1&2\\3&4\end{bmatrix}$, $B = \begin{bmatrix}5&6\\7&8\end{bmatrix}$.
Work each of the four slots as a row·column dot product:
$(1,1)$: row 1 · col 1 $= (1)(5)+(2)(7) = 5+14 = 19$.
$(1,2)$: row 1 · col 2 $= (1)(6)+(2)(8) = 6+16 = 22$.
$(2,1)$: row 2 · col 1 $= (3)(5)+(4)(7) = 15+28 = 43$.
$(2,2)$: row 2 · col 2 $= (3)(6)+(4)(8) = 18+32 = 50$.
$$AB = \begin{bmatrix}19 & 22\\43 & 50\end{bmatrix}.$$
A column vector is just a matrix with one column, so the same rule applies. Compute $\begin{bmatrix}2&1\\1&3\end{bmatrix}\begin{bmatrix}4\\5\end{bmatrix}$.
Row 1 · the column $= (2)(4)+(1)(5) = 8+5 = 13$.
Row 2 · the column $= (1)(4)+(3)(5) = 4+15 = 19$.
$$\begin{bmatrix}2&1\\1&3\end{bmatrix}\begin{bmatrix}4\\5\end{bmatrix} = \begin{bmatrix}13\\19\end{bmatrix}.$$
Notice $(2\times2)(2\times1) = (2\times1)$ — a vector in, a vector out. This is the view of a matrix as a machine that transforms vectors.
Compute $CD$ for $C = \begin{bmatrix}1&2&3\\4&5&6\end{bmatrix}$ $(2\times3)$ and $D = \begin{bmatrix}7&8\\9&10\\11&12\end{bmatrix}$ $(3\times2)$.
Inner numbers $3 = 3$ ✓, so $CD$ exists and is $2\times2$. Each entry dots a length-3 row with a length-3 column:
$(1,1) = (1)(7)+(2)(9)+(3)(11) = 7+18+33 = 58.$
$(1,2) = (1)(8)+(2)(10)+(3)(12) = 8+20+36 = 64.$
$(2,1) = (4)(7)+(5)(9)+(6)(11) = 28+45+66 = 139.$
$(2,2) = (4)(8)+(5)(10)+(6)(12) = 32+50+72 = 154.$
$$CD = \begin{bmatrix}58 & 64\\139 & 154\end{bmatrix}.$$
§6The Big Warning — Order Matters
With ordinary numbers, $5 \times 3 = 3 \times 5$. With matrices this fails. In general $AB \neq BA$. Matrix multiplication is not commutative. The order you multiply in changes the answer — sometimes it even changes whether the product exists at all.
Take the same $A = \begin{bmatrix}1&2\\3&4\end{bmatrix}$ and $B = \begin{bmatrix}5&6\\7&8\end{bmatrix}$. We found $AB = \begin{bmatrix}19&22\\43&50\end{bmatrix}$. Now compute $BA$:
$(1,1) = (5)(1)+(6)(3) = 5+18 = 23.$
$(1,2) = (5)(2)+(6)(4) = 10+24 = 34.$
$(2,1) = (7)(1)+(8)(3) = 7+24 = 31.$
$(2,2) = (7)(2)+(8)(4) = 14+32 = 46.$
$$BA = \begin{bmatrix}23 & 34\\31 & 46\end{bmatrix} \neq \begin{bmatrix}19 & 22\\43 & 50\end{bmatrix} = AB.$$
Same two matrices, completely different products. This is why we always say "$A$ times $B$" carefully, and why we distinguish left-multiply from right-multiply.
§7The Identity Matrix — Multiplication's "1"
The identity matrix $I_n$ is the $n\times n$ matrix with $1$s on the main diagonal and $0$s everywhere else. For example $I_2 = \begin{bmatrix}1&0\\0&1\end{bmatrix}$ and $I_3 = \begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix}.$
The identity earns its name: multiplying by it changes nothing, exactly like the number $1$.
For any $m\times n$ matrix $A$, we have $I_m A = A$ and $A I_n = A$. Multiplying by the identity (on either side, with the matching size) returns $A$ unchanged.
Let $A = \begin{bmatrix}3&1\\2&5\end{bmatrix}$. Then
$$AI = \begin{bmatrix}3&1\\2&5\end{bmatrix}\begin{bmatrix}1&0\\0&1\end{bmatrix} = \begin{bmatrix}3&1\\2&5\end{bmatrix} = A,$$
and $IA = A$ as well. This is the matrix we are chasing when we look for an inverse: $A^{-1}A = I$ means "$A^{-1}$ undoes $A$ back to the do-nothing matrix."
§8The Laws That Still Hold
Multiplication loses commutativity — but it keeps most other good behaviour. Here are the laws you may rely on (assuming all sizes line up so the products exist).
- Associative: $A(BC) = (AB)C$. You may regroup, just never reorder.
- Left distributive: $A(B + C) = AB + AC$.
- Right distributive: $(B + C)A = BA + CA$.
- Scalars slide: $k(AB) = (kA)B = A(kB)$ for any scalar $k$.
- Identity: $IA = A$ and $AI = A$.
- Transpose reverses order: $(AB)^{\mathsf{T}} = B^{\mathsf{T}} A^{\mathsf{T}}$.
Let $A = \begin{bmatrix}1&2\\0&1\end{bmatrix}$, $B = \begin{bmatrix}2&0\\1&3\end{bmatrix}$, $C = \begin{bmatrix}1&1\\2&0\end{bmatrix}$.
§9Three Surprises That Trip Everyone Up
Matrix multiplication breaks a few "rules" you've trusted since school. Knowing these in advance saves you from confident mistakes.
§10Powers of a Square Matrix
For a square matrix $A$, we define $A^2 = AA$, $A^3 = AAA$, and in general $A^k = A \cdot A \cdots A$ ($k$ times). By convention $A^0 = I$. Powers are only defined for square matrices, because only then does $A\cdot A$ satisfy the size rule.
Let $A = \begin{bmatrix}1&1\\0&1\end{bmatrix}$. Find $A^3$.
$A^2 = \begin{bmatrix}1&1\\0&1\end{bmatrix}\begin{bmatrix}1&1\\0&1\end{bmatrix} = \begin{bmatrix}1&2\\0&1\end{bmatrix}.$
$A^3 = A^2 A = \begin{bmatrix}1&2\\0&1\end{bmatrix}\begin{bmatrix}1&1\\0&1\end{bmatrix} = \begin{bmatrix}1&3\\0&1\end{bmatrix}.$
A clean pattern emerges: $A^k = \begin{bmatrix}1&k\\0&1\end{bmatrix}$. Matrix powers often reveal patterns like this — they are the engine behind modelling repeated processes (population growth, web-page ranking, and more).
§11The Payoff — Systems Become a Single Equation
Here is where all of this pays off, and it connects straight back to everything you solved in Week 1. A whole system of linear equations collapses into one tidy matrix product.
The system $\begin{cases}2x + y = 5 \\ x + 3y = 10\end{cases}$ can be written as $A\mathbf{x} = \mathbf{b}$:
$$\underbrace{\begin{bmatrix}2&1\\1&3\end{bmatrix}}_{A}\underbrace{\begin{bmatrix}x\\y\end{bmatrix}}_{\mathbf{x}} = \underbrace{\begin{bmatrix}5\\10\end{bmatrix}}_{\mathbf{b}}.$$
Multiply out the left side using the row·column rule: row 1 gives $2x + y$, row 2 gives $x + 3y$. Setting these equal to $\mathbf{b}$ reproduces the original two equations exactly. The matrix product is the system.
And now the connection to Lecture 6: if $A$ is invertible, the solution is simply $\mathbf{x} = A^{-1}\mathbf{b}$. (Here the answer is $x = 1$, $y = 3$.) The inverse and multiplication are two halves of the same machine.
§12Practice — Test Yourself
Find $AB$ where $A = \begin{bmatrix}2&0\\-1&3\end{bmatrix}$, $B = \begin{bmatrix}1&4\\2&-1\end{bmatrix}$.
$A$ is $4\times2$ and $B$ is $4\times2$. (a) Does $AB$ exist? (b) Does $A^{\mathsf{T}}B$ exist, and what size?
For $A = \begin{bmatrix}0&1\\0&0\end{bmatrix}$ and $B = \begin{bmatrix}0&0\\1&0\end{bmatrix}$, compute $AB$ and $BA$ and compare.
- Every entry of $AB$ is one row of $A$ dotted with one column of $B$.
- The product exists only when columns of $A$ = rows of $B$; the answer is $(\text{rows of }A)\times(\text{cols of }B)$.
- Order matters: $AB \neq BA$ in general, so you can never "cancel" a matrix.
- The identity $I$ does nothing; the inverse $A^{-1}$ undoes $A$ back to $I$.
- Multiplication is composition of transformations — that's why it's defined this way.
Bring any leftover questions to the tutorial or to TA office hours — and welcome back to Lecture 6, where this all pays off in the inverse.