Two transformations applied one after the other are again a transformation, so it has a matrix of its own, and working out what that matrix is defines multiplication.
The previous lesson established the fact this one rests on: a linear map is determined by where it sends the basis vectors, and the matrix of the map is the list of those images, written as columns. So sends to and to , and is the combination of the columns weighted by the components of .
Deriving the product
Let and be matrices, and consider doing first and then . The composite map sends to , and it is linear, since a composition of maps that each preserve combinations preserves combinations. Being linear, it has a matrix, which is written and read right to left: acts first.
Finding that matrix requires no new idea, only the rule that a matrix is the list of the images of the basis vectors. Column of is the image of under the composite, which is . But is column of . So:
Column of is applied to column of .
That is the definition of matrix multiplication, and every other description of it is this one rearranged. Since applied to a vector takes the dot product of each row of with that vector, the entry in row and column of is row of dotted with column of , which is the rule usually taught first and which looks arbitrary until it is seen to come from composition.
Take and . Column one of is . Column two is . So . Checking one entry by the row rule: row one of is , and dotted with column one of , which is , it gives , matching.
The shape rule now explains itself. To form , the vectors that produces must be vectors that can eat, so the number of rows of must equal the number of columns of . An by matrix times an by matrix gives an by matrix, and any other combination is not a failure of arithmetic but a request to feed a map something it does not take.
Example. With and , compute .
Column one of is applied to column one of , that is . Column two is . So , which is nothing like .
Now you. With and , compute .
Answer
Column one is . Column two is . So .
Order matters
Multiplication of numbers is commutative and multiplication of matrices is not, and this is a feature rather than a defect: composing operations in the other order genuinely gives a different result, and the algebra had better say so.
Take , a quarter turn anticlockwise, with matrix , and , the shear . Then means shear first, and its columns are and , so . Meanwhile means turn first, with columns and , giving .
The two differ, and the difference is visible in a single vector: sends to , while sends it to . Anyone can reproduce this with a book. Rotate it a quarter turn about the vertical axis and then a quarter turn about the horizontal one, then start again and do the two in the opposite order: the book ends up in two different orientations. Three-dimensional rotations do not commute, and the matrices that represent them must fail to commute in exactly the same pattern.
What does survive is associativity: , always. No calculation is needed, because both sides describe the map "do , then , then ", and function composition is associative by its nature. Proving it from the entry formula takes half a page of index manipulation and produces less understanding. Distributivity, , follows from linearity in the same way, addition of matrices being entry by entry.
The identity satisfies , since it does nothing before or after anything else. And powers make sense for square matrices: is the map applied twice. Shearing by and shearing by again gives , a shear by , which is the algebra confirming that two equal slides compose into a double slide.
What composition proves
Because the product means composition, computing a product sometimes proves a theorem in trigonometry for free.
Rotating by and then by must be the same as rotating by . Write the two matrices out, using the rotation matrix derived in the previous lesson. Column one of is applied to , which is
that is, . But that column must be the first column of , namely . Comparing components gives both angle addition formulas at once. Anyone who has forgotten which sign goes where can rebuild them from the geometry in a minute.
Example. With the quarter turn and the shear above, compute and identify it.
Column one is and column two is , so , which is . Two quarter turns make a half turn, and a half turn negates every vector.
Now you. Compute for the shear .
Answer
from the doubling rule above, and has columns and . So , a shear by , as three equal slides should be.
Zero products and other surprises
The algebra of matrices departs from the algebra of numbers in a second way, which is worth meeting deliberately rather than discovering in the middle of a proof.
Let , the projection onto the horizontal axis, and , the projection onto the vertical. Neither is the zero matrix. Their product is: column one of is , and column two is , so is the zero matrix, and so is . Geometrically this is obvious once seen. flattens everything onto the vertical axis, and then flattens the vertical axis onto the origin, so the composite destroys everything.
The consequence is that does not imply that or is zero, and therefore that cancellation is illegal: from you may not conclude . The offending matrices are exactly those that collapse something, which the lesson on determinants identifies precisely.
A second surprise: satisfies , since projecting twice is the same as projecting once. Among numbers only and do that, and among matrices there are infinitely many such idempotents, one for every projection.
Transpose
The transpose swaps rows and columns, so the columns of become the rows of . If , its rows are and , so . Transposing an by matrix gives an by one, and transposing twice returns the original.
Two facts about it are used constantly. First, the dot product is a matrix product in disguise: , a one by matrix times an by one matrix, giving a single number. Second, the transpose reverses products, . The reason is visible through the dot product: for all vectors, , and the matrix that behaves this way on every pair of vectors is unique. A matrix with is symmetric, which requires it to be square and which turns out to be the best-behaved case in the whole subject, as the final lesson shows.
Example. Verify for and .
from above, whose rows are and , so . Now and , and has column one and column two . The two agree.
Now you. Is the product of two symmetric matrices always symmetric?
Answer
No. when both are symmetric, and equals only if the two commute. For a concrete failure take and , both symmetric: has columns and , so , whose transpose is , a different matrix.
What it costs
Multiplying two by matrices by the definition takes multiplications per entry and there are entries, so multiplications in total. For that is operations, about a second at a billion per second, and for it is , which is why the size of the matrices in a machine learning model is a budget rather than a detail.
The exponent three is not forced. In 1969 Volker Strassen found a way to multiply two by two blocks using seven multiplications instead of eight, at the cost of extra additions, and applying it recursively gives an exponent of . At that is instead of , a real saving, though the constants and the numerical stability are worse and library implementations only switch to it for large matrices. Later work has pushed the exponent below , but those algorithms have constants so large that no practical matrix is big enough to benefit, and nobody knows the true minimum. The obvious lower bound is , since every entry must at least be read.
Honest limits
Matrix multiplication is associative and distributive but not commutative, and there is no division. The natural question is whether a given matrix can be undone at all, and the answer is sometimes no, as the projection above shows: once a vector has been flattened onto the horizontal axis, no transformation can recover which height it came from.
There is also a warning about notation. Because means " first", chains of matrices read backwards relative to the order the operations happen, and this is a permanent source of error when translating a geometric description into a product. Some fields, including parts of computer graphics, avoid it by writing vectors as rows on the left instead, so that means first. Both conventions are in use, they produce transposed matrices, and mixing them silently gives wrong answers.
The next lesson takes up the undoing question. It turns out that a single number computed from the entries decides whether a square matrix can be inverted, and that the number has a plain geometric meaning: it is how much the transformation multiplies area.