§ 01Conformability — When Can You Multiply?
Before you can multiply two matrices, you must check that their dimensions are compatible. This is the single most common source of errors for students new to linear algebra.
If A is an m × k matrix and B is a k × n matrix, then the product AB is defined and produces an m × n matrix. The inner dimensions must match, A has k columns and B has k rows.
Inner dimensions must be equal. Outer dimensions give the shape of the result.
A useful memory trick: write the two size pairs side by side, (m × k) · (k × n). The bold inner values must match; they "cancel", leaving (m × n) as the result size.
| A size | B size | AB defined? | Result size |
|---|---|---|---|
| 2 × 3 | 3 × 4 | ✓ Yes | 2 × 4 |
| 3 × 2 | 2 × 5 | ✓ Yes | 3 × 5 |
| 4 × 4 | 4 × 4 | ✓ Yes | 4 × 4 |
| 2 × 3 | 4 × 2 | ✗ No | — (3 ≠ 4) |
| 1 × 5 | 5 × 1 | ✓ Yes | 1 × 1 (scalar) |
| 5 × 1 | 1 × 5 | ✓ Yes | 5 × 5 |
§ 02The Formula — (AB)ᵢⱼ = Row i · Column j
Each entry of the product matrix is computed as the dot product of a row from A with a column from B. Specifically:
Entry (i, j) of AB = the dot product of row i of A with column j of B.
To compute the entry in position (i, j) of the product:
- Take row i of A as a list of numbers.
- Take column j of B as a list of numbers.
- Multiply corresponding entries together and sum them all up.
This must be done for every position (i, j) in the result matrix: that's m × n dot products in total, each of length k.
Compute AB where:
- (AB)₁₁: Row 1 of A = [1, 2], Col 1 of B = [5, 7]. Dot product: 1·5 + 2·7 = 5 + 14 = 19
- (AB)₁₂: Row 1 of A = [1, 2], Col 2 of B = [6, 8]. Dot product: 1·6 + 2·8 = 6 + 16 = 22
- (AB)₂₁: Row 2 of A = [3, 4], Col 1 of B = [5, 7]. Dot product: 3·5 + 4·7 = 15 + 28 = 43
- (AB)₂₂: Row 2 of A = [3, 4], Col 2 of B = [6, 8]. Dot product: 3·6 + 4·8 = 18 + 32 = 50
Compute AB where A is 2 × 3 and B is 3 × 2. Result will be 2 × 2.
- (AB)₁₁ = 2(1) + 0(4) + 1(−1) = 2 + 0 − 1 = 1
- (AB)₁₂ = 2(2) + 0(0) + 1(3) = 4 + 0 + 3 = 7
- (AB)₂₁ = 1(1) + 3(4) + (−1)(−1) = 1 + 12 + 1 = 14
- (AB)₂₂ = 1(2) + 3(0) + (−1)(3) = 2 + 0 − 3 = −1
§ 03Why AB ≠ BA — Non-Commutativity
One of the most important (and surprising) facts in linear algebra is that matrix multiplication is not commutative. The order matters enormously. There are three distinct ways this can go wrong:
If A is 2×3 and B is 3×4, then AB is 2×4. But BA would require (3×4)(2×3): inner dims 4 ≠ 2, so BA is undefined.
If A is 2×3 and B is 3×2, then AB is 2×2 and BA is 3×3. They cannot be equal because they have different shapes.
Even for square matrices of the same size, AB and BA are almost never equal. See Example 3 below for a concrete demonstration.
AB = BA when one matrix is a scalar multiple of I, when both are diagonal, or in special structured cases. These are the exception, not the rule.
Let A and B be:
- Compute AB: (1·1+2·3, 1·0+2·1) = (7, 2) and (0·1+1·3, 0·0+1·1) = (3, 1).
- Compute BA: (1·1+0·0, 1·2+0·1) = (1, 2) and (3·1+1·0, 3·2+1·1) = (3, 7).
§ 04The Identity Matrix — The Matrix "1"
The identity matrix Iₙ is the n×n matrix with 1s on the main diagonal and 0s everywhere else. It plays the role of the number 1 in ordinary multiplication:
More generally, if A is m×n, then A·Iₙ = A and Iₘ·A = A.
Let A be the 2×2 matrix from Example 1. Verify that AI₂ = A.
- Row 1 of A · Col 1 of I₂: [1,2]·[1,0]ᵀ = 1·1 + 2·0 = 1 ✓
- Row 1 of A · Col 2 of I₂: [1,2]·[0,1]ᵀ = 1·0 + 2·1 = 2 ✓
- Row 2 of A · Col 1 of I₂: [3,4]·[1,0]ᵀ = 3 ✓
- Row 2 of A · Col 2 of I₂: [3,4]·[0,1]ᵀ = 4 ✓
Matrix Powers
For a square matrix A, matrix powers are defined by repeated multiplication: A² = AA, A³ = AAA, and so on. A⁰ = I by convention. Powers obey the usual index laws: AᵐAⁿ = Aᵐ⁺ⁿ. However, (AB)² ≠ A²B² in general, since (AB)² = ABAB, not AABB.
Find A² where A = [[2, 1], [1, 3]].
- (A²)₁₁ = 2·2 + 1·1 = 5
- (A²)₁₂ = 2·1 + 1·3 = 5
- (A²)₂₁ = 1·2 + 3·1 = 5
- (A²)₂₂ = 1·1 + 3·3 = 10
§ 05Algebraic Properties of Matrix Multiplication
While commutativity fails, most other familiar algebraic laws do hold. These properties allow matrices to be manipulated in proofs and computations with confidence.
| Property | Formula | Note |
|---|---|---|
| Associativity | (AB)C = A(BC) | Always true — multiplication order is preserved |
| Distributivity (left) | A(B + C) = AB + AC | Matrix addition distributes over multiplication |
| Distributivity (right) | (A + B)C = AC + BC | Both sides must be considered separately |
| Scalar multiplication | c(AB) = (cA)B = A(cB) | Scalar factors can move freely |
| Transpose of product | (AB)ᵀ = BᵀAᵀ | Order reverses when taking transpose |
| Identity | AI = IA = A | Identity matrix acts like the number 1 |
| Zero matrix | A·0 = 0·A = 0 | The zero matrix annihilates everything |
Using A = [[1,2],[3,4]] and B = [[5,6],[7,8]] from Example 1, where AB = [[19,22],[43,50]].
- (AB)ᵀ = [[19,43],[22,50]]
- Bᵀ = [[5,7],[6,8]], Aᵀ = [[1,3],[2,4]]
- BᵀAᵀ: (1,1) = 5·1+7·2 = 19; (1,2) = 5·3+7·4 = 43; (2,1) = 6·1+8·2 = 22; (2,2) = 6·3+8·4 = 50
- BᵀAᵀ = [[19,43],[22,50]] = (AB)ᵀ ✓
§ 06More Worked Examples
Compute AB where A = [[1,0,2],[0,3,0],[4,0,1]] and B = [[1,1,0],[2,0,1],[0,3,1]].
- Row 1 of A = [1,0,2]: (AB)₁₁ = 1+0+0 = 1; (AB)₁₂ = 1+0+6 = 7; (AB)₁₃ = 0+0+2 = 2
- Row 2 of A = [0,3,0]: (AB)₂₁ = 0+6+0 = 6; (AB)₂₂ = 0+0+0 = 0; (AB)₂₃ = 0+3+0 = 3
- Row 3 of A = [4,0,1]: (AB)₃₁ = 4+0+0 = 4; (AB)₃₂ = 4+0+3 = 7; (AB)₃₃ = 0+0+1 = 1
The product Ax, where x is a column vector, equals a linear combination of the columns of A, with the entries of x as coefficients. This is a fundamental geometric view of matrix multiplication.
Let A = [[1,3],[2,4]] and x = [2, −1]ᵀ.
- Standard approach: (1·2+3·(−1), 2·2+4·(−1)) = (−1, 0).
- Column view: Ax = 2·[1,2]ᵀ + (−1)·[3,4]ᵀ = [2,4]ᵀ + [−3,−4]ᵀ = [−1, 0]ᵀ. Same answer.
When a row vector yᵀ premultiplies A, the result is a linear combination of the rows of A, with the entries of yᵀ as coefficients.
Let yᵀ = [3, 1] and A = [[2, 5],[1, 0]]. Then yᵀA = 3·[2,5] + 1·[1,0] = [6,15]+[1,0] = [7, 15].
An (m×1) column vector times a (1×n) row vector gives an (m×n) matrix: a rank-1 matrix called the outer product.
Let u = [1, 2, 3]ᵀ (3×1) and vᵀ = [4, 5] (1×2). Then uvᵀ is 3×2.
- Row 1: 1·[4,5] = [4, 5]
- Row 2: 2·[4,5] = [8, 10]
- Row 3: 3·[4,5] = [12, 15]
§ 07Block Matrix Multiplication
Large matrices can be partitioned into smaller blocks (submatrices), and multiplication can be performed block-by-block, exactly as if the blocks were individual entries, provided the block dimensions are conformable.
The inner block dimensions must match, just as with ordinary entries.
Block multiplication is especially powerful when some blocks are zero matrices or identity matrices: the product simplifies dramatically without computing every entry. It is also the foundation for many efficient computational algorithms and for the analysis of structured matrices such as block-diagonal or block-triangular matrices.
Partition A = [[I₂ | C], [0 | D]] and B = [[E], [F]] where I₂ is 2×2 identity and all blocks are conformable.
- Top block of AB: I₂·E + C·F = E + CF (the identity block leaves E unchanged).
- Bottom block of AB: 0·E + D·F = DF.
Unlike ordinary numbers, matrices can satisfy AB = 0 (the zero matrix) with neither A nor B being zero. These are called zero divisors.
Let A = [[1,2],[2,4]] and B = [[2,−4],[−1,2]].
- (AB)₁₁ = 1·2+2·(−1) = 0; (AB)₁₂ = 1·(−4)+2·2 = 0
- (AB)₂₁ = 2·2+4·(−1) = 0; (AB)₂₂ = 2·(−4)+4·2 = 0
§ 08Common Mistakes
§ 09Practice Quiz — Matrix Multiplication
- Conformability: A is (3×4), B is (4×2). Inner dims match (both 4).
- Result takes outer dims: 3 × 2.
- (AB)₁₂ = Row 1 of A · Col 2 of B = [2,1]·[4,0]ᵀ = 2·4 + 1·0 = 8.
- Matrix multiplication is NOT commutative. AB ≠ BA in general.
- It holds only in special cases: e.g., when one matrix is a scalar multiple of I, or when both are diagonal.
- (AB)₂₁ = Row 2 of A · Col 1 of B = [0,2]·[3,4]ᵀ = 0·3 + 2·4 = 8.
- (AB)ᵀ = BᵀAᵀ, the order reverses when taking the transpose of a product.
- This generalises: (ABC)ᵀ = CᵀBᵀAᵀ.
- (AB)₁₁ = Row 1·Col 1 = [1,2]·[0,1]ᵀ = 0+2 = 2.
- Full product: AB = [[2,1],[4,3]].
- Multiplying any matrix by the identity matrix returns the original matrix: A·I = I·A = A.
- (AB)₁₁ = 1·1+1·(−1) = 0; (AB)₁₂ = 1·0+1·0 = 0.
- (AB)₂₁ = 0·1+0·(−1) = 0; (AB)₂₂ = 0.
- AB = 0 (the zero matrix), yet neither A nor B is zero. This is a zero divisor example.
- Associativity: (AB)C = A(BC). The grouping of multiplications does not matter.
- This is different from commutativity (AB = BA), which does NOT hold in general.
- B = I₂, so AB = A. Therefore (AB)₂₂ = A₂₂ = 4.
- Alternatively: (AB)₂₂ = Row 2 of A · Col 2 of B = [1,4]·[0,1]ᵀ = 0+4 = 4.
Keep practising!