Recipe
Multiply two matrices
Use when: you have two matrices A (n\times k) and B (k\times m) and need the full product AB
Goal: the complete n\times m product matrix, every entry computed and checked
Taught in Matrix multiplication
Quick recipe
-
1
A's column count has to equal B's row count for AB to exist at all. If it does, the product's shape is A's row count by B's column count — the two "outer" numbers.
Example
A=\begin{pmatrix} 2 & 1 \\ -1 & 3 \end{pmatrix} is 2\times2; B=\begin{pmatrix} 4 & -2 & 1 \\ 3 & 3 & 5 \end{pmatrix} is 2\times3. The inner numbers, both 2, agree — AB exists, and its shape is 2\times3 (A's 2 rows by B's 3 columns).
- the inner dimensions agree — continue to Step 2.
- the inner dimensions disagree — AB doesn't exist; stop here — there's no partial or approximate product to fall back on.
Why: the product is only defined because the size of what A's rows produce matches the size B's columns need to consume — the same requirement that made matrix-vector multiplication well-defined, now applied to every column of B at once.
-
2
Entry (i,j) of AB is row i of A dotted with column j of B: multiply matching entries together and add.
Example
Entry (1,1): row 1 of A is (2,1), column 1 of B is (4,3). (2)(4)+(1)(3)=8+3=11.
Why: this is the definition itself, (AB)_{ij}=\sum_t a_{it}b_{tj}, with nothing more than a labeled dot product behind the notation.
-
3
Keep the same row of A fixed while sliding across each column of B to finish that row of AB; then move to the next row of A and repeat.
Example
Row 1 of A against columns 2 and 3 of B gives (2)(-2)+(1)(3)=-1 and (2)(1)+(1)(5)=7, completing row 1 of AB as (11,-1,7). Row 2 of A, (-1,3), against all three columns of B then gives (5,11,14). \boxed{AB=\begin{pmatrix}11 & -1 & 7 \\ 5 & 11 & 14\end{pmatrix}}
Why: fixing one row of A while sliding across B's columns reuses the same numbers for several dot products in a row, instead of re-reading A from scratch for every single entry.
-
4
Column j of AB is also A times column j of B — a weighted sum of A's own columns, weighted by the entries of B's column j. This computes (or checks) one whole column at once instead of one entry at a time.
Example
Column 1 of B is (4,3). Weighting A's columns by these: 4\begin{pmatrix}2\\-1\end{pmatrix}+3\begin{pmatrix}1\\3\end{pmatrix}=\begin{pmatrix}8\\-4\end{pmatrix}+\begin{pmatrix}3\\9\end{pmatrix}=\begin{pmatrix}11\\5\end{pmatrix} — matching column 1 of AB from Step 3 exactly.
Why: row-times-column and column-times-combination are the same arithmetic grouped two different ways, so they always agree — matching answers here rules out a wrong-entry slip in Steps 2–3, without redoing every dot product.
Common mistakes
- Multiplying entry by entry (matching positions), the way matrix addition works — matrix multiplication is never elementwise.
- Checking only that the two matrices "look about the same size," instead of specifically comparing A's column count to B's row count — AB and BA can have completely different shapes, or one can exist while the other doesn't.
- Losing track of which row of A and which column of B is current partway through a larger product, and dotting the wrong pair together.
- Dropping a negative sign midway through a running sum with several terms.
- Assuming AB=BA — matrix multiplication is not commutative in general, even when both products are defined and the same size.