If you've seen it before, you might remember a confusing rule about rows and columns, dot products, and a lot of finger-pointing. The "how" can seem strange and arbitrary.
The secret to understanding it is to ignore the "how" for a moment and focus on the "why." The "why" comes directly from our second view of matrices: a matrix is a transformation.
What happens if you want to apply two transformations in a row? First, you rotate space 90 degrees counter-clockwise. Then, you shear space horizontally.
Let's call the rotation matrix and the shear matrix . Applying to a vector gives you a new vector, let's call it . Then, applying to gives you the final vector, .
The central question of matrix multiplication is this: Is there a single, new matrix that represents this entire two-step process? Can we find a matrix that does the rotation *and then* the shear all in one go, such that ?
Yes. That new matrix is the product of and .
Matrix multiplication is the composition of linear transformations. It's how we combine multiple transformations into a single, equivalent one.
Order Matters!
Thinking about transformations makes it immediately obvious why the order of matrix multiplication is critical. Rotating then shearing gives you one result. Shearing then rotating gives you a completely different result! This is why, in general, is not the same as . Matrix multiplication is not commutative.
The Dimension Rule
To multiply two matrices and to get , the inner dimensions must match.
If is (m rows, n columns) and is (n rows, p columns), then you can multiply them. The resulting matrix will have the outer dimensions: .
The Calculation Rule
The entry in the -th row and -th column of the product matrix is the dot product of the -th row of and the -th column of .
Example:
is , is . The result will be .
(1st row, 1st col) = (Row 1 of A) · (Col 1 of B)
(1st row, 2nd col) = (Row 1 of A) · (Col 2 of B)
(2nd row, 1st col) = (Row 2 of A) · (Col 1 of B)
(2nd row, 2nd col) = (Row 2 of A) · (Col 2 of B)
Result:
- The "Why": Matrix multiplication is the composition of transformations.
- The "How": The entry in row , column is the dot product of row of the first matrix and column of the second.
- The Rule: The inner dimensions must match: .
- The Warning: Order matters! In general, .
Up Next: Now that we know the rules, let's look at some special "character" matrices—matrices with unique properties that play important roles in the story, like the Identity matrix and the Inverse matrix.