Skip to content

Why matrix multiplication is defined this way

7 min read

Short answer

A matrix is a recipe for a linear map, and the product ABAB is defined so that it is the recipe for doing BB first, then AA. The row-times-column rule is not a convention someone chose; it is the only formula that makes (AB)x=A(Bx)(AB)\mathbf{x}=A(B\mathbf{x}) true for every vector x\mathbf{x}.

Steps1Start with a vector x2Apply B to get Bx3Apply A to that to get A(Bx)4The single matrix AB does both at onceAB means: first B, then A
Multiplying matrices is composing machines. The product matrix is the single machine that behaves like the two chained together.

A matrix is what a linear map does to the basis

A linear map is completely determined by what it does to the standard basis vectors e1,…,en\mathbf{e}_1,\dots,\mathbf{e}_n, because every vector is a combination of them and linearity lets you carry the combination through. The columns of the matrix are exactly those images: column jj of BB is BejB\mathbf{e}_j.

So a matrix is a table of "where does each basis vector land?" Once you know that, Bx=x1(col 1)+x2(col 2)+⋯B\mathbf{x}=x_1(\text{col }1)+x_2(\text{col }2)+\cdots is not a rule to memorize. It is just linearity.

Deriving the formula

Ask what the composite map does to a basis vector ej\mathbf{e}_j. First BB sends it to column jj of BB, which is ∑kbkjek\sum_k b_{kj}\mathbf{e}_k. Then AA acts on that sum, and linearity gives ∑kbkj Aek\sum_k b_{kj}\,A\mathbf{e}_k. Reading off the ii-th coordinate of this result:

(AB)ij=∑kaik bkj.(AB)_{ij}=\sum_{k} a_{ik}\,b_{kj}.

That is the row-times-column rule. Row ii of AA is paired with column jj of BB because column jj of BB says how much of each AekA\mathbf{e}_k to mix in. Nothing else would make the composite work.

What the definition forces

Sizes. To feed the output of BB into AA, the output dimension of BB must equal the input dimension of AA. That is why an m×nm\times n matrix times an n×pn\times p matrix is defined and the inner sizes must match.

Associativity. Composing functions is associative, so (AB)C=A(BC)(AB)C=A(BC) for free. You never need to expand indices to prove it.

No commutativity. "Put on socks, then shoes" differs from "shoes, then socks". In general AB≠BAAB\neq BA, and one product can exist while the other does not.

Not entrywise. Multiplying matching entries (the Hadamard product) is a different operation. It does not compose maps, so it does not behave like a transformation at all.

Worked example

Let A=(1201)A=\begin{pmatrix}1&2\\0&1\end{pmatrix} (a shear) and B=(0−110)B=\begin{pmatrix}0&-1\\1&0\end{pmatrix} (a 90° rotation). Compute ABAB and BABA and check ABAB on e1\mathbf{e}_1.

Rows of AA against columns of BB:

AB=(1⋅0+2⋅11⋅(−1)+2⋅00⋅0+1⋅10⋅(−1)+1⋅0)=(2−110).AB=\begin{pmatrix}1\cdot0+2\cdot1 & 1\cdot(-1)+2\cdot0\\ 0\cdot0+1\cdot1 & 0\cdot(-1)+1\cdot0\end{pmatrix}=\begin{pmatrix}2&-1\\1&0\end{pmatrix}.

BA=(0⋅1+(−1)⋅00⋅2+(−1)⋅11⋅1+0⋅01⋅2+0⋅1)=(0−112).BA=\begin{pmatrix}0\cdot1+(-1)\cdot0 & 0\cdot2+(-1)\cdot1\\ 1\cdot1+0\cdot0 & 1\cdot2+0\cdot1\end{pmatrix}=\begin{pmatrix}0&-1\\1&2\end{pmatrix}.

They differ, so order matters.

Check: Be1=(0,1)B\mathbf{e}_1=(0,1), then A(0,1)=(2,1)A(0,1)=(2,1). That is column 1 of ABAB, as the definition promises.

Try it yourself

For A=(1101)A=\begin{pmatrix}1&1\\0&1\end{pmatrix} and B=(1011)B=\begin{pmatrix}1&0\\1&1\end{pmatrix}, compute ABAB and BABA. Are they equal?

Show the answer

AB=(1⋅1+1⋅11⋅0+1⋅10⋅1+1⋅10⋅0+1⋅1)=(2111)AB=\begin{pmatrix}1\cdot1+1\cdot1 & 1\cdot0+1\cdot1\\ 0\cdot1+1\cdot1 & 0\cdot0+1\cdot1\end{pmatrix}=\begin{pmatrix}2&1\\1&1\end{pmatrix} and BA=(1112)BA=\begin{pmatrix}1&1\\1&2\end{pmatrix}. They are not equal, so these two matrices do not commute.

Keep going with practice

Vidi's linear algebra lessons build matrices from the maps they describe, so the multiplication rule stops feeling arbitrary.