The Compatibility Rule
Unlike scalar multiplication, you cannot just multiply any two matrices together. They must satisfy a strict dimension compatibility rule: the number of columns in the first matrix must equal the number of rows in the second matrix.
If matrix A has size m × n and matrix B has size p × q, the product AB is defined if and only if:
n = p
The resulting product matrix C will have the size m × q (the outer dimensions of A and B).
The Row-by-Column Dot Product
To calculate the element in Row i, Column j of the product matrix, you take the dot product of Row i of the first matrix and Column j of the second matrix. You multiply corresponding elements and add the results together:
C[i][j] = A[i][0] × B[0][j] + A[i][1] × B[1][j] + ... + A[i][n-1] × B[n-1][j]
Worked Example
Let's multiply a 2x3 matrix A and a 3x2 matrix B:
| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 |
| 9 | 1 |
| 0 | 2 |
The inner dimensions match (3 columns in A, 3 rows in B), so multiplication is valid. The product AB will be a 2x2 matrix C:
- C[0][0] (Row 1 of A • Column 1 of B):
(1 × 7) + (2 × 9) + (3 × 0) = 7 + 18 + 0 = 25. - C[0][1] (Row 1 of A • Column 2 of B):
(1 × 8) + (2 × 1) + (3 × 2) = 8 + 2 + 6 = 16. - C[1][0] (Row 2 of A • Column 1 of B):
(4 × 7) + (5 × 9) + (6 × 0) = 28 + 45 + 0 = 73. - C[1][1] (Row 2 of A • Column 2 of B):
(4 × 8) + (5 × 1) + (6 × 2) = 32 + 5 + 12 = 49.
The product matrix C = AB is:
| 25 | 16 |
| 73 | 49 |
Key Algebraic Properties
- Non-Commutative: In general, matrix multiplication is not commutative: AB ≠ BA. Swapping the order changes the row-column pairings, and often even makes the dimensions incompatible.
- Identity Element: Multiplying any matrix by the Identity matrix preserves it: AI = IA = A.
- Associative: (AB)C = A(BC).