How composing two linear maps leads to the matrix product, when sizes are compatible, why order matters, and the rules for the identity matrix, associativity, the transpose of a product and blocks.
Lean a drawing to the right with a shear, then stretch it to twice its width. If the stretch comes first instead, does the drawing end up the same? Applying one linear transformation after another gives a single linear transformation, and its matrix is the product of the two matrices. This lesson builds that product column by column, says when it is defined and why the order of the factors matters, and collects the rules for regrouping, transposing and splitting a product into blocks.
Key terms
Composition of linear maps
Definition Vectors are columns, and on this page a tuple such as (x,y) written inline stands for the column with those entries. Let T be a linear transformation from Rp to Rn and U a linear transformation from Rn to Rm. The composition U∘T, read as U after T, is the map from Rp to Rm given by
(U∘T)(x)=U(T(x)),
so T acts first and U acts on its output. The composition makes sense because every output of T lies in Rn, the domain of U. It is linear, since for all u,v in Rp and all real a,b
U(T(au+bv))=U(aT(u)+bT(v))=aU(T(u))+bU(T(v)).
If B is the standard matrix of T and A is the standard matrix of U, then column j of the standard matrix of U∘T is U(T(ej))=Abj, where bj=T(ej) is column j of B. The matrix with these columns is the product AB, defined in the next card.
In plain words The output of the first map becomes the input of the second. In the matrix AB the map that acts first stands on the right, next to the vector it acts on.
Example Let S be the matrix of the shear (x,y)↦(x+y,y) and D the matrix of the horizontal stretch (x,y)↦(2x,y),
S=[1011],D=[2001].
To shear first and then stretch, follow the standard unit vectors. The shear leaves e1 at (1,0) and the stretch moves it to (2,0). The shear moves e2 to (1,1) and the stretch moves that to (2,1). These images are the columns of
DS=[2021].
As a check, the shear sends (3,−1) to (2,−1) and the stretch sends that to (4,−1), while the rows of DS give 2⋅3+2⋅(−1)=4 and 0⋅3+1⋅(−1)=−1.
Matrix product and compatible sizes
Definition Let A be an m×n matrix and B an n×p matrix with columns b1,…,bp. The product AB is the m×p matrix
AB=[Ab1Ab2⋯Abp].
Its entry in row i and column j is row i of A times column j of B,
(AB)ij=k=1∑naikbkj=ai1b1j+⋯+ainbnj.
The sizes are compatible when the number of columns of A equals the number of rows of B, and only then is AB defined. An m×n matrix times an n×p matrix is an m×p matrix. The shared inner size n counts the coordinates handed from the first map to the second, and the outer sizes are the output size m and the input size p. For every x in Rp the product satisfies (AB)x=A(Bx), so AB is the matrix of the composition that applies B first and then A. The product is not formed by multiplying entries in matching positions.
In plain words Multiply the left matrix into each column of the right matrix. The inside sizes must agree, and the outside sizes give the size of the answer.
Example Take
A=[132−1],B=[210−113].
The sizes 2×2 and 2×3 are compatible, so AB is defined and is 2×3. Multiplying A into the columns (2,1), (0,−1) and (1,3) of B gives (4,5), (−2,1) and (7,0), so
AB=[45−2170].
The row rule agrees. For example, row 2 of A times column 3 of B is 3⋅1+(−1)⋅3=0. The product BA is not defined, because B has 3 columns and A has only 2 rows.
Noncommutativity of matrix multiplication
Definition Matrix multiplication is not commutative, which means AB and BA need not be equal. If AB is defined, then BA may be undefined. If A is m×n and B is n×m, both products are defined but have sizes m×m and n×n, which differ when m=n. When A and B are both n×n with n≥2, the two products have the same size and can still differ. Matrices of size 1×1 always commute, because they multiply like numbers. Some pairs do commute, for example two diagonal matrices of the same size, a square matrix and the identity matrix of its size, or a square matrix and itself. Before exchanging two factors, check that AB=BA for those particular matrices.
In plain words Applying two maps in the opposite order usually gives a different map, so the factors of a product cannot be swapped freely.
Example With the shear S and the stretch D from the first card,
DS=[2021],SD=[2011].
Follow the input (1,1). Shearing first gives (2,1), and stretching then gives (4,1), which is DS times (1,1). Stretching first gives (2,1), and shearing then gives (3,1), which is SD times (1,1). In the first order the stretch also doubles the sideways shift made by the shear. In the second order the shift is added after the stretch and is not doubled.
Associativity and the identity matrix
Definition If A is m×n, B is n×p and C is p×q, then
(AB)C=A(BC).
To prove it, apply both sides to any x in Rq and use the rule (XY)x=X(Yx) for products,
Two matrices that agree on every vector agree on each ej, so they have the same columns and are equal. This is why a product such as ABC needs no parentheses. The identity matrix In is the n×n matrix with columns e1,…,en, that is, with 1 in every diagonal position and 0 elsewhere. It satisfies Inx=x for every x in Rn, and for every m×n matrix A
ImA=A=AIn.
In plain words In a chain of maps the order of application is fixed, but you may choose which neighboring pair to combine first. Regrouping is allowed and reordering is not. The identity matrix represents the map that leaves every vector where it is.
Example Let u=(1,2), v=(3,−1) and w=(2,5). Grouping on the left first forms a 2×2 matrix,
uv⊤=[36−1−2],
and then (uv⊤)w=(6−5,12−10)=(1,2). Grouping on the right first gives the 1×1 matrix v⊤w=6−5=1, so u(v⊤w)=(1,2) with far less arithmetic. For the identity, take the 2×3 matrix E with columns (1,0), (0,1) and (1,1). Then I2E=E and EI3=E, while the product I3E is not even defined.
Transpose of a product
Definition If A is m×n and B is n×p, then
(AB)⊤=B⊤A⊤.
Both sides are p×m. To prove it, compare the entries in row i and column j,
where the middle step uses ajkbki=bkiajk for real numbers. The order of the factors reverses. The product A⊤B⊤ in the original order is in general a different matrix, and it may not be defined at all.
In plain words To transpose a product, transpose each factor and reverse their order.
Example With A and B from the matrix product card, (AB)⊤ is the 3×2 matrix whose columns (4,−2,7) and (5,1,0) are the rows of AB. The reversed product of transposes gives the same matrix,
B⊤A⊤=2011−13[123−1]=4−27510.
The other order A⊤B⊤ would be a 2×2 matrix times a 3×2 matrix, which is not defined.
Block multiplication
Definition Cut the rows and the columns of a matrix A into consecutive groups, which splits A into blocks Aik, and cut the rows and the columns of B into groups as well, giving blocks Bkj. The partitions conform when the column groups of A have the same sizes, in the same order, as the row groups of B. Then AB can be computed block by block. Its block in block row i and block column j is
k∑AikBkj,
the entry formula with blocks in place of numbers. With two block columns in A and two block rows in B, for instance, the top left block of AB is A11B11+A12B21. Conforming partitions make every product AikBkj defined and give the terms of each sum the same size. Each product must keep its order, because blocks are matrices and need not commute. The row groups of A and the column groups of B may be chosen freely, and they become the row and column groups of AB.
In plain words Treat the blocks like entries and keep each left factor on the left. This works only when the inner size is cut the same way in both matrices.
Example Cut the 2×3 matrix M after its second column, so that M=[I2c] with c=(2,−1), and cut x=(3,4,2) after its second entry to match,
Mx=[10012−1]342.
The block rule gives
Mx=I2[34]+[2−1]⋅2=[34]+[4−2]=[72],
and the rows of M confirm it, since 3+0+4=7 and 0+4−2=2. Cutting x after its first entry instead would pair a block of two columns with a block of one entry, and the block products would not be defined.
Check yourself
Let A be a 3×2 matrix and B a 2×4 matrix. Which of the products AB, BA, B⊤A⊤ and A⊤B⊤ are defined, and what are their sizes?
Show the answer
The product AB is defined, since A has 2 columns and B has 2 rows, and it is 3×4. The product BA is not defined, because B has 4 columns but A has 3 rows. The transposes are B⊤, of size 4×2, and A⊤, of size 2×3, so B⊤A⊤ is defined, is 4×3 and equals (AB)⊤. The product A⊤B⊤ would need the 3 columns of A⊤ to match the 4 rows of B⊤, so it is not defined. Keeping the original order when transposing a product is a common mistake.
Let R be the counterclockwise quarter turn and P the projection onto the horizontal axis,
R=[01−10],P=[1000].
Compute RP and PR, apply both to e1, and explain the difference.
Show the answer
Apply the left matrix to each column of the right one. The columns of P are (1,0) and (0,0), which R sends to (0,1) and (0,0). The columns of R are (0,1) and (−1,0), which P sends to (0,0) and (−1,0). So
RP=[0100],PR=[00−10].
The product RP projects first, which leaves e1 at (1,0), and then turns it to (0,1). The product PR turns first, which sends e1 to (0,1), and the projection then sends that vertical vector to 0. So RPe1=(0,1) while PRe1=0.
The 3×3 matrices below are cut after the second row and after the second column, with c=(2,−1) and d=(1,3) in their top right blocks.
M=1000102−11,N=100010131.
Use block multiplication to find MN, check one entry directly, and decide whether MN=NM.
Show the answer
Both matrices are cut into groups of sizes 2 and 1, for rows and for columns, so the partitions conform. In block form
M=[I20⊤c1],N=[I20⊤d1],
where 0⊤ is the 1×2 zero row. The four blocks of MN are
Here c0⊤ is a 2×1 matrix times a 1×2 matrix, which is the 2×2 zero matrix. Since c+d=(3,2),
MN=100010321.
Directly, row 1 of M times column 3 of N is 1⋅1+0⋅3+2⋅1=3, which matches. The same block computation for NM gives the top right block d+c, which equals c+d, and the other blocks are unchanged, so NM=MN. These two matrices commute, as does every pair of matrices of this block form, but that is a fact about this special form, not a general rule.
May we count page visits to understand which courses and learning features are useful? Cloudflare collects visit and performance statistics, without your account details or answers. Your choice does not affect access. Details