Turn then shear, or shear then turn: the same two moves in two orders. Watch the two pictures end up different.
Order matters
A quarter turn and a shear, in the two orders.
Two copies of the same picture. Each gets the same two moves, a quarter turn and a shear, in opposite orders.
Describe this picture
Two panels side by side (one above the other on a phone), each with a faint square grid and the same letter F on it. On the left the grid turns a quarter turn anticlockwise and then shears, sliding each row sideways by its height. On the right it shears first and then turns. Each panel holds its end picture, and its single matrix appears in its corner: on the left , on the right . The two end pictures differ. A transport plays, pauses and steps; there is no other control.
One map, then another
In A matrix moves the plane a matrix was the table of where the two unit arrows and land: the first column says where goes, the second where goes. This page uses two such maps.
The first is a quarter turn anticlockwise. It sends to and to :
The second is a shear. It slides every point sideways by its height, so goes to . It leaves where it is and pushes over to :
Now do one, then the other. Turn first, then shear. Where do the unit arrows end up? Follow each one through both maps:
- turns to , and the shear pushes that to .
- turns to , and the shear leaves it at .
Two arrows and their landing places: that is a matrix. The single map “turn, then shear” is
It is the left panel’s end state at the top of the page. This matrix is the product of the two, written .
Why the order is written backwards
Look at the order of the names. The turn happens first, but it is written on the right. Here is why. A point is turned to , and then that is sheared:
The first map stands next to , because it touches first. So read a product from right to left: means “do , then do ”.
One check remains. Is “one map, then another” always a matrix? It is, because each map keeps the linear rule from A matrix moves the plane. If keeps scaling and adding, and so does , then
So the chain is linear too, and a linear map of the plane is fixed by where it sends the two unit arrows.
The other order
Now shear first, then turn:
- is not moved by the shear, and the turn sends it to .
- is sheared to , and the turn sends that to .
That is not , the matrix of the first order.
Watch the clip again and compare the two end pictures: the same picture, the same two moves, two different results. In general . Some pairs do agree, such as two turns, but you can’t count on it.
Columns of the product
The same reasoning works for any two matrices. Column of , which I call , is where sends the unit arrow . Then sends it on to . So:
To multiply two matrices, multiply the first by each column of the second, one at a time. Each of those is a matrix times a vector, which you already know how to do.
Columns of the product
A = [1 2; 3 4] moves the columns of B = [0 1; 1 0].
The columns of B as two arrows, b_1 = (0, 1) and b_2 = (1, 0). The grid is about to move by A.
Describe this picture
A grid with the two columns of , and , drawn as arrows from the origin. The grid then moves by . This flips the plane over, so the grid first stretches, then folds across a dotted mirror line, lying flat on it for a moment, and opens out. Each arrow is carried to times that column, and . Those two arrows are the columns of , and they are written into the product matrix in the corner one column at a time, . Readouts give where the two arrows are. There is no control.
Watch where the two arrows land. Each one is a column of pushed through , and nothing else.
Shapes that fit
Matrices need not be square. Say is : rows and columns, so it takes numbers in. Each column of goes into , so each column of must have numbers: has rows. Let have columns; on this page is only that count. Then
The two inside numbers must match, and the two outside numbers give the shape of the answer. A matrix can’t multiply another : it takes 3 numbers in, and the columns of the second have only 2.
Row times column
Each column is a matrix times a vector, and A matrix moves the plane computed that one row at a time: entry is row of dotted with the vector. So one entry of the product is one row of dotted with one column of :
Here is the entry of in row and column , counted from 1, and runs along the row of and down the column of together.
Try it on and :
The answer is with its two columns swapped. That makes sense from the columns picture: sends to and to , so the product’s first column is ‘s second.
Watch out
A product is not entry times entry. Multiplying the entries in the same places gives , which is not and is not “one map, then another”. Every entry of a product is a whole row against a whole column.
Column times row
There is a third way to get the same numbers. Take column of and row of . A column of numbers times a row of numbers makes a full table: the entry in row and column is . Add these tables for to , and each entry collects , the same sum as before.
For the same and :
Three ways, one answer. Columns tell you what the product does to the unit arrows. Rows times columns are the quickest by hand. Columns times rows show a product as a sum of simple pieces, a view that comes back often in linear algebra.
The rules
Grouping does not matter. . Both sides mean “do , then , then ”, so they are the same chain of maps, and you may drop the brackets: .
Order does matter. and are usually different, as the two panels showed. For the and above, : on the left, swaps the rows of instead of the columns.
The identity changes nothing. The map that leaves both unit arrows where they are is the identity matrix,
Doing nothing before or after a map leaves the map as it was. For numbers, is with 1s down the diagonal and 0s elsewhere.
Blocks multiply like entries. Cut into a left and a right block of columns, and , and cut into a top and a bottom block of rows, and , at the same place. Then
the column-times-row rule with blocks in place of single columns and rows. The order inside each block product stays as it was.
Worked example
1. The two orders. Rotate, then shear:
Entry by entry: row 1 times column 1 is , row 1 times column 2 is , and row 2 gives and .
Check with the arrows: and , the two columns. Shear, then rotate: , with and . Follow the point to see the difference: the first order takes it to , the second to .
2. Swapping columns and rows. With and , swaps the columns of and swaps its rows. The column-times-row sum above gives the same .
3. Shapes. Now take a new matrix and a new matrix :
is : the first entry is , and in all
is . Here the two orders don’t even have the same shape.
Predict before you compute: a matrix times a matrix gives what shape? : 20 entries, each one row of 3 numbers dotted with one column of 3.
Where you’ll meet this
Graphics. A drawing program that scales a shape, turns it and tilts it multiplies the three matrices once and applies the single product to every corner of the shape. One product, thousands of corners. To move shapes too, graphics programs add one extra coordinate so that a move becomes a matrix as well.
Layers of a neural network. Two layers that take 784 numbers to 128 and then 128 to 10 hold a and a matrix: 101,632 numbers. If nothing happened between the layers, their product would be a single matrix of 7,840 numbers doing the same job. Real networks put a step that is not linear between the layers, and that step is what stops the two from merging into one.
Filters in a chain. In signal processing a filter is a matrix too, so two filters in a chain are a product of two matrices.
In signal processing · cascaded filters
Discrete convolution, in the signal processing course, shows that two filters in a chain give the same output in either order. That is a special property of filters, which are linear and time-invariant. Matrices in general do not have it, as the turn and the shear on this page show.
Reference card
| Quantity | Formula | Notes |
|---|---|---|
| Product as a map | do first, then | |
| By columns | column of is | times each column of |
| By entries | row of dotted with column of | |
| By pieces | column of , row of | |
| Shapes | the inside numbers must match | |
| Grouping | the same chain of maps | |
| Order | in general | turn then shear differs from shear then turn |
| Identity | 1s on the diagonal, 0s elsewhere |