All lessons

Matrix multiplication is composition

Day
6 of 40
Length
2:30
Textbook
Lay §2.1
Syllabus
Groundwork before Lesson 10

AB means do B first, then A; the product's columns are A applied to B's columns.

Yesterday each matrix moved the whole plane once. Today asks what happens when you do two moves in a row, and whether the result is still one matrix. The answer defines matrix multiplication, so the rule for multiplying matrices comes straight from the geometry instead of from a memorized recipe. Day 7 needs this product to say what it means to undo a matrix.

Each section below opens with a problem. Try it before you open the walkthrough, even if you only get partway. From here on, ı^\hat\imath and ȷ^\hat\jmath mean the same green and red basis arrows that Day 5 called e1\mathbf e_1 and e2\mathbf e_2.

Composition

The shear S=[1101]S = \begin{bmatrix} \green{1} & \red{1} \\ \green{0} & \red{1} \end{bmatrix} acts on the plane first, and then the quarter turn R=[0−110]R = \begin{bmatrix} \green{0} & \red{-1} \\ \green{1} & \red{0} \end{bmatrix} acts on the result. Where does x=[11]\yellow{\mathbf x} = \begin{bmatrix} 1 \\ 1 \end{bmatrix} end up?

Walk through the solution

We know how to apply one matrix at a time, so we do exactly that, starting with the move that happens first.

By Day 4's column picture, SxS\yellow{\mathbf x} is 11 times the first column of SS plus 11 times the second column:

Sx=1[10]+1[11]=[21]S\yellow{\mathbf x} = 1\begin{bmatrix} 1 \\ 0 \end{bmatrix} + 1\begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} 2 \\ 1 \end{bmatrix}

Now the quarter turn acts on (2,1)(2, 1), so we use the entries 22 and 11 as weights on the columns of RR:

R[21]=2[01]+1[−10]=[−12]R\begin{bmatrix} 2 \\ 1 \end{bmatrix} = 2\begin{bmatrix} 0 \\ 1 \end{bmatrix} + 1\begin{bmatrix} -1 \\ 0 \end{bmatrix} = \begin{bmatrix} -1 \\ 2 \end{bmatrix}

The point ends at (−1,2)(-1, 2). We wrote the whole trip as R(Sx)R(S\yellow{\mathbf x}), with SS closest to x\yellow{\mathbf x} because it acts first.

Following one point works, but a second point would mean doing both multiplications again. Day 5 showed that a whole linear move is known once you know where ı^\hat\imath and ȷ^\hat\jmath land, so the next problem follows just those two arrows.

Find a single matrix MM that does "shear with SS, then turn with RR" in one step. Check it on x=(1,1)\yellow{\mathbf x} = (1, 1).

Walk through the solution

The columns of MM must be the places where ı^\green{\hat\imath} and ȷ^\red{\hat\jmath} end up after both moves, so we follow each arrow through SS and then RR.

  1. 1

    The shear sends ı^\green{\hat\imath} to the first column of SS, which is (1,0)(1, 0). The turn then sends (1,0)(1, 0) to the first column of RR, which is (0,1)(0, 1). So the first column of MM is (0,1)\green{(0, 1)}.

  2. 2
  3. 3
  4. 4

Each column of MM came from sending a column of SS through RR. That pattern is the whole rule for multiplying matrices.

The vector x = (1, 1) hops through the shear S to (2, 1) and then through the quarter turn R to (−1, 2). A single teal arc labelled RS jumps straight from (1, 1) to (−1, 2). Beside the grid, RS is the matrix with columns (0, 1) and (−1, 1).

Two moves in a row are one matrix

The single matrix for "do BB, then do AA" is called the product ABAB. For the shear and the turn, RS=[0−111]RS = \begin{bmatrix} 0 & -1 \\ 1 & 1 \end{bmatrix}, and it satisfies

A(Bx)=(AB)xfor every x.A(B\mathbf x) = (AB)\mathbf x \quad\text{for every } \mathbf x.

Read a product from right to left. The matrix next to x\mathbf x touches it first, so in RSRS the shear happens first.

The reason this works for every x\mathbf x is Day 4's column picture. Write B=[b1⋯bp]B = \begin{bmatrix} \mathbf b_1 & \cdots & \mathbf b_p \end{bmatrix}. Then

A(Bx)=A(x1b1+⋯+xpbp)=x1 Ab1+⋯+xp Abp=[Ab1⋯Abp]x.\begin{aligned} A(B\mathbf x) &= A(x_1\mathbf b_1 + \cdots + x_p\mathbf b_p) \\ &= x_1\,A\mathbf b_1 + \cdots + x_p\,A\mathbf b_p \\ &= \begin{bmatrix} A\mathbf b_1 & \cdots & A\mathbf b_p \end{bmatrix}\mathbf x. \end{aligned}

The second line uses the linearity of AA from Day 5. Because a product is just "one move after another", grouping never matters: A(BC)=(AB)CA(BC) = (AB)C, since both sides mean "do CC, then BB, then AA". Doing the same move kk times is written AkA^k, and A0=IA^0 = I. Powers come back with eigenvalues on Days 28 to 33.

Drag x\yellow{\mathbf x} below. The dashed arrows show the two hops, and the teal arrow is the single jump that RSRS makes.

Drag x\mathbf x so that applying SS and then RR carries it onto the ringed point [−13]\begin{bmatrix} -1 \\ 3 \end{bmatrix}.
SxRSx
Sx=[21]S\mathbf x = \begin{bmatrix} 2 \\ 1 \end{bmatrix}
R(Sx)=[−12]R(S\mathbf x) = \textcolor{#3DD6B5}{\begin{bmatrix} -1 \\ 2 \end{bmatrix}}
RS=[0−111]RS = \begin{bmatrix} \textcolor{#7BC96F}{0} & \textcolor{#F2665E}{-1} \\ \textcolor{#7BC96F}{1} & \textcolor{#F2665E}{1} \end{bmatrix}

The column rule

Problem 2 found the product by sending each column of SS through RR. The next problem runs that recipe on two matrices with no picture attached, so you can see it is pure arithmetic.

Let A=[2−111]A = \begin{bmatrix} \green{2} & \red{-1} \\ \green{1} & \red{1} \end{bmatrix} and B=[111−1]B = \begin{bmatrix} \yellow{1} & \blue{1} \\ \yellow{1} & \blue{-1} \end{bmatrix}. Compute ABAB, entering it row by row.

Walk through the solution

The columns of ABAB are AA applied to the columns of BB, so we compute two matrix–vector products.

The first column of BB is (1,1)\yellow{(1, 1)}. Its entries are the weights on the columns of AA:

Ab1=1[21]+1[−11]=[12]A\yellow{\mathbf b_1} = 1\begin{bmatrix} 2 \\ 1 \end{bmatrix} + 1\begin{bmatrix} -1 \\ 1 \end{bmatrix} = \begin{bmatrix} 1 \\ 2 \end{bmatrix}

The second column of BB is (1,−1)\blue{(1, -1)}:

Ab2=1[21]+(−1)[−11]=[30]A\blue{\mathbf b_2} = 1\begin{bmatrix} 2 \\ 1 \end{bmatrix} + (-1)\begin{bmatrix} -1 \\ 1 \end{bmatrix} = \begin{bmatrix} 3 \\ 0 \end{bmatrix}

Stacking the two results as columns gives AB=[1320]AB = \begin{bmatrix} 1 & 3 \\ 2 & 0 \end{bmatrix}. Each column of the answer is a combination of the columns of AA, and the matching column of BB supplies the weights.

Matrix product

If AA is m×nm \times n and BB is n×pn \times p with columns b1,…,bp\mathbf b_1, \dots, \mathbf b_p, then the product ABAB is the m×pm \times p matrix

AB=A[b1⋯bp]=[Ab1⋯Abp].AB = A\begin{bmatrix} \mathbf b_1 & \cdots & \mathbf b_p \end{bmatrix} = \begin{bmatrix} A\mathbf b_1 & \cdots & A\mathbf b_p \end{bmatrix}.

Each column of ABAB is a combination of the columns of AA, with weights from the matching column of BB.

The picture below carries the grid through AA. A column of BB says how many green steps and how many red steps to take on that carried grid, so you can place each column of ABAB by counting.

Drag the yellow and blue dots to Ab1A\mathbf b_1 and Ab2A\mathbf b_2. Count steps along the blue grid that AA carries.
Ab₁Ab₂
A=[2−111]A = \begin{bmatrix} \textcolor{#7BC96F}{2} & \textcolor{#F2665E}{-1} \\ \textcolor{#7BC96F}{1} & \textcolor{#F2665E}{1} \end{bmatrix}
B=[111−1]B = \begin{bmatrix} \textcolor{#FFD447}{1} & \textcolor{#5BC0EB}{1} \\ \textcolor{#FFD447}{1} & \textcolor{#5BC0EB}{-1} \end{bmatrix}
[Ab1Ab2]=?[111−1]\begin{bmatrix} A\mathbf b_1 & A\mathbf b_2 \end{bmatrix} \overset{?}{=} \begin{bmatrix} \textcolor{#FFD447}{1} & \textcolor{#5BC0EB}{1} \\ \textcolor{#FFD447}{1} & \textcolor{#5BC0EB}{-1} \end{bmatrix}

The column rule also runs backward. If you know AA and a column of ABAB, you can recover the matching column of BB by asking which weights on the columns of AA produce it.

Let A=[121−1]A = \begin{bmatrix} \green{1} & \red{2} \\ \green{1} & \red{-1} \end{bmatrix}. The first column of ABAB is [5−1]\begin{bmatrix} 5 \\ -1 \end{bmatrix}. Find the first column b1\mathbf b_1 of BB.

Walk through the solution

The first column of ABAB is Ab1A\mathbf b_1. Call the entries of b1\mathbf b_1 pp and qq. Then we need

p[11]+q[2−1]=[5−1].p\begin{bmatrix} 1 \\ 1 \end{bmatrix} + q\begin{bmatrix} 2 \\ -1 \end{bmatrix} = \begin{bmatrix} 5 \\ -1 \end{bmatrix}.

Matching entries gives p+2q=5p + 2q = 5 and p−q=−1p - q = -1. Subtracting the second equation from the first removes pp and leaves 3q=63q = 6, so q=2q = 2. Then p=−1+q=1p = -1 + q = 1.

So b1=(1,2)\mathbf b_1 = (1, 2). Check: 1(1,1)+2(2,−1)=(5,−1)1(1, 1) + 2(2, -1) = (5, -1).

The first column of ABAB is the ringed point [5−1]\begin{bmatrix} 5 \\ -1 \end{bmatrix}. Set the two entries of b1\mathbf b_1 so that Ab1A\mathbf b_1 lands on it.
A=[121−1]A = \begin{bmatrix} \textcolor{#7BC96F}{1} & \textcolor{#F2665E}{2} \\ \textcolor{#7BC96F}{1} & \textcolor{#F2665E}{-1} \end{bmatrix}
Ab1=0[11]+0[2−1]=[00]\begin{aligned} A\mathbf b_1 &= 0\textcolor{#7BC96F}{\begin{bmatrix} 1 \\ 1 \end{bmatrix}} + 0\textcolor{#F2665E}{\begin{bmatrix} 2 \\ -1 \end{bmatrix}} \\ &= \textcolor{#3DD6B5}{\begin{bmatrix} 0 \\ 0 \end{bmatrix}} \end{aligned}

The row–column rule

The column rule builds a whole column at a time. Often you need only one entry, and there is a faster way to get it.

Let A=[12−34]A = \begin{bmatrix} 1 & 2 \\ -3 & 4 \end{bmatrix} and B=[20−1513]B = \begin{bmatrix} 2 & 0 & -1 \\ 5 & 1 & 3 \end{bmatrix}. Find only the entry of ABAB in row 2, column 3. Which numbers from AA and BB did you actually use?

Walk through the solution

The entry in row 2, column 3 is the second entry of column 3, and column 3 of ABAB is Ab3A\mathbf b_3 with b3=(−1,3)\mathbf b_3 = (-1, 3):

Ab3=−1[1−3]+3[24]=[−1+63+12]=[515]A\mathbf b_3 = -1\begin{bmatrix} 1 \\ -3 \end{bmatrix} + 3\begin{bmatrix} 2 \\ 4 \end{bmatrix} = \begin{bmatrix} -1 + 6 \\ 3 + 12 \end{bmatrix} = \begin{bmatrix} 5 \\ 15 \end{bmatrix}

The entry we want is 1515. Now look at how the 1515 was made: (−3)(−1)+(4)(3)(-3)(-1) + (4)(3). The numbers −3-3 and 44 are row 2 of AA, and −1-1 and 33 are column 3 of BB. Nothing else was needed.

A 2 by 2 matrix with rows (1, 2) and (−3, 4) times a 2 by 3 matrix with rows (2, 0, −1) and (5, 1, 3) equals the matrix with rows (12, 2, 5) and (14, 4, 15). Row 2 of the first factor, column 3 of the second and the entry 15 are boxed in orange, with the sizes 2 × 2, 2 × 3 and 2 × 3 written underneath and the sum (−3)(−1) + 4 · 3 = 15 below.

Row times column gives one entry

To get the entry in row ii and column jj of ABAB, walk along row ii of AA and down column jj of BB together, multiply matching entries, and add:

(AB)ij=ai1b1j+ai2b2j+⋯+ainbnj.(AB)_{ij} = a_{i1}b_{1j} + a_{i2}b_{2j} + \cdots + a_{in}b_{nj}.

For this to work, row ii of AA and column jj of BB must have the same length. So AA needs as many columns as BB has rows.

That length condition gives a quick size check. Write the sizes under the factors. In the figure, 2×2‾2 \times \underline{2} times 2‾×3\underline{2} \times 3 has matching inner numbers, and the outer numbers say the answer is 2×32 \times 3. The other order, BABA, is 2×3‾2 \times \underline{3} times 2‾×2\underline{2} \times 2, and the inner numbers 33 and 22 differ, so BABA is not defined.

AA is 3×53 \times 5 and BB is 5×25 \times 2. Which statement is true?

The row–column rule also works for a whole row at once. Row ii of ABAB uses only row ii of AA, so rowi(AB)=rowi(A) B\text{row}_i(AB) = \text{row}_i(A)\,B. Here is row 2 of the product above, computed that way:

[−34][20−1513]=−3[20−1]+4[513]=[14415]\begin{aligned} \begin{bmatrix} -3 & 4 \end{bmatrix}\begin{bmatrix} 2 & 0 & -1 \\ 5 & 1 & 3 \end{bmatrix} &= -3\begin{bmatrix} 2 & 0 & -1 \end{bmatrix} + 4\begin{bmatrix} 5 & 1 & 3 \end{bmatrix} \\ &= \begin{bmatrix} 14 & 4 & 15 \end{bmatrix} \end{aligned}

The row is a combination of the rows of BB, with weights from row ii of AA. Day 8 uses this row version to show that every row operation from Day 3 is a multiplication by a matrix.

Order matters

Now turn first and shear second. Find the matrix for this order and enter it row by row. Then find where (1,1)(1, 1) lands, and compare with RSRS from Problem 2.

Walk through the solution

The turn acts first, so the product is SRSR with RR on the right. Its columns are SS applied to the columns of RR.

The first column of RR is (0,1)(0, 1), and S(0,1)=0[10]+1[11]=[11]S(0, 1) = 0\begin{bmatrix} 1 \\ 0 \end{bmatrix} + 1\begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} 1 \\ 1 \end{bmatrix}.

The second column of RR is (−1,0)(-1, 0), and S(−1,0)=−1[10]+0[11]=[−10]S(-1, 0) = -1\begin{bmatrix} 1 \\ 0 \end{bmatrix} + 0\begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} -1 \\ 0 \end{bmatrix}.

So SR=[1−110]SR = \begin{bmatrix} 1 & -1 \\ 1 & 0 \end{bmatrix}, and SR[11]=[11]+[−10]=[01]SR\begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} 1 \\ 1 \end{bmatrix} + \begin{bmatrix} -1 \\ 0 \end{bmatrix} = \begin{bmatrix} 0 \\ 1 \end{bmatrix}.

In the other order, RS=[0−111]RS = \begin{bmatrix} 0 & -1 \\ 1 & 1 \end{bmatrix} sent (1,1)(1, 1) to (−1,2)(-1, 2). The same two moves in a different order put the same point in a different place.

Two grids side by side. On the left, shear then rotate: the yellow tip of x ends at (−1, 2), and RS has columns (0, 1) and (−1, 1). On the right, rotate then shear: the tip ends at (0, 1), and SR has columns (1, 1) and (−1, 0).

Matrices usually do not commute

For most pairs of matrices, AB≠BAAB \neq BA. When AB=BAAB = BA does hold, we say that AA and BB commute. The identity II commutes with every square matrix, because IA=A=AIIA = A = AI.

Some pairs do commute. Slide kk below until both orders move the unit square to the same place.

Slide kk until ABAB and BABA move the square to the same place.
A=[2101]B=[1k03]A = \begin{bmatrix} \textcolor{#E8ECF1}{2} & \textcolor{#E8ECF1}{1} \\ \textcolor{#E8ECF1}{0} & \textcolor{#E8ECF1}{1} \end{bmatrix} \qquad B = \begin{bmatrix} 1 & \textcolor{#FF8A3D}{k} \\ 0 & 3 \end{bmatrix}
AB=[2503]AB = \begin{bmatrix} \textcolor{#7BC96F}{2} & \textcolor{#F2665E}{5} \\ \textcolor{#7BC96F}{0} & \textcolor{#F2665E}{3} \end{bmatrix}
BA=[2203]BA = \begin{bmatrix} \textcolor{#7BC96F}{2} & \textcolor{#F2665E}{2} \\ \textcolor{#7BC96F}{0} & \textcolor{#F2665E}{3} \end{bmatrix}

Zero products

Ordinary numbers have a rule that if ab=0ab = 0, then a=0a = 0 or b=0b = 0. The next problem tests whether that rule survives for matrices.

Let M=[1224]M = \begin{bmatrix} 1 & 2 \\ 2 & 4 \end{bmatrix}. Find a matrix BB whose columns are both nonzero and different from each other, with MB=[0000]MB = \begin{bmatrix} 0 & 0 \\ 0 & 0 \end{bmatrix}.

Walk through the solution

By the column rule, MBMB is zero exactly when MM sends each column of BB to 0\mathbf 0. So we look for nonzero vectors (p,q)(p, q) with M(p,q)=0M(p, q) = \mathbf 0.

p[12]+q[24]=[p+2q2p+4q]p\begin{bmatrix} 1 \\ 2 \end{bmatrix} + q\begin{bmatrix} 2 \\ 4 \end{bmatrix} = \begin{bmatrix} p + 2q \\ 2p + 4q \end{bmatrix}

Both entries are zero when p+2q=0p + 2q = 0, because the second entry is twice the first. Taking q=1q = 1 gives p=−2p = -2, and taking q=−2q = -2 gives p=4p = 4. So one answer is

B=[−241−2]MB=[−2+24−4−4+48−8]=[0000]\begin{aligned} B &= \begin{bmatrix} -2 & 4 \\ 1 & -2 \end{bmatrix} \\ MB &= \begin{bmatrix} -2 + 2 & 4 - 4 \\ -4 + 4 & 8 - 8 \end{bmatrix} = \begin{bmatrix} 0 & 0 \\ 0 & 0 \end{bmatrix} \end{aligned}

This worked because the columns of MM lie on one line, so a combination of them can cancel to zero.

Drag the two columns of BB to two different spots, neither of them the origin, so that MM sends both of them to 0\mathbf 0.
b₁b₂
M=[1224]M = \begin{bmatrix} \textcolor{#7BC96F}{1} & \textcolor{#F2665E}{2} \\ \textcolor{#7BC96F}{2} & \textcolor{#F2665E}{4} \end{bmatrix}
B=[1210]B = \begin{bmatrix} \textcolor{#FFD447}{1} & \textcolor{#5BC0EB}{2} \\ \textcolor{#FFD447}{1} & \textcolor{#5BC0EB}{0} \end{bmatrix}
MB=[3264]MB = \begin{bmatrix} \textcolor{#3DD6B5}{3} & \textcolor{#3DD6B5}{2} \\ \textcolor{#3DD6B5}{6} & \textcolor{#3DD6B5}{4} \end{bmatrix}

Cancelling is not allowed

Two more rules from ordinary numbers fail for matrices.

  • AB=0AB = 0 does not force A=0A = 0 or B=0B = 0. Problem 7 is an example.
  • AB=ACAB = AC does not force B=CB = C. In Problem 7, MB=M⋅0MB = M\cdot 0 even though B≠0B \neq 0.

Both failures happen when AA flattens the plane onto a line, so two different inputs can land on the same output. Day 7 names these matrices singular and shows that cancelling is safe for every other square matrix.

Matrix sums

Adding and scaling matrices works the way it did for vectors on Day 1, one entry at a time.

Let A=[1−2304−1]A = \begin{bmatrix} 1 & -2 & 3 \\ 0 & 4 & -1 \end{bmatrix} and B=[210−325]B = \begin{bmatrix} 2 & 1 & 0 \\ -3 & 2 & 5 \end{bmatrix}. Compute 3A−B3A - B, entering it row by row.

Walk through the solution

Scale first, then subtract entry by entry. Tripling AA gives [3−69012−3]\begin{bmatrix} 3 & -6 & 9 \\ 0 & 12 & -3 \end{bmatrix}. Subtracting BB in each position:

[3−2−6−19−00−(−3)12−2−3−5]=[1−79310−8]\begin{bmatrix} 3 - 2 & -6 - 1 & 9 - 0 \\ 0 - (-3) & 12 - 2 & -3 - 5 \end{bmatrix} = \begin{bmatrix} 1 & -7 & 9 \\ 3 & 10 & -8 \end{bmatrix}

Sums go entry by entry

The sum A+BA + B adds matching entries, and the scalar multiple rArA multiplies every entry by rr. A sum is defined only when AA and BB have the same size, because every entry needs a partner. Sums and products mix the way numbers do, as long as you keep the order of each product: A(B+C)=AB+ACA(B + C) = AB + AC and (B+C)A=BA+CA(B + C)A = BA + CA.

The transpose

Take A=[12−34]A = \begin{bmatrix} 1 & 2 \\ -3 & 4 \end{bmatrix} and B=[20−1513]B = \begin{bmatrix} 2 & 0 & -1 \\ 5 & 1 & 3 \end{bmatrix} from Problem 5, where AB=[122514415]AB = \begin{bmatrix} 12 & 2 & 5 \\ 14 & 4 & 15 \end{bmatrix}. Flip each matrix so its rows become its columns. Then multiply the flipped BB by the flipped AA and compare with the flipped ABAB.

Walk through the solution

Flipping AA turns its rows (1,2)(1, 2) and (−3,4)(-3, 4) into columns, and flipping BB does the same with its two rows of length 3:

AT=[1−324],BT=[2501−13]A^T = \begin{bmatrix} 1 & -3 \\ 2 & 4 \end{bmatrix}, \qquad B^T = \begin{bmatrix} 2 & 5 \\ 0 & 1 \\ -1 & 3 \end{bmatrix}

BTB^T is 3×2‾3 \times \underline{2} and ATA^T is 2‾×2\underline{2} \times 2, so BTATB^TA^T is defined and is 3×23 \times 2. Row by row with the row–column rule:

  1. 1

    Row 1 of BTB^T is (2,5)(2, 5). Pairing it with the columns of ATA^T gives 2(1)+5(2)=122(1) + 5(2) = 12 and 2(−3)+5(4)=142(-3) + 5(4) = 14.

  2. 2
  3. 3

So BTAT=[121424515]B^TA^T = \begin{bmatrix} 12 & 14 \\ 2 & 4 \\ 5 & 15 \end{bmatrix}, which is exactly ABAB flipped. The other order, ATBTA^TB^T, is 2×22 \times 2 times 3×23 \times 2, which is not even defined.

Transpose

The transpose ATA^T of an m×nm \times n matrix AA is the n×mn \times m matrix whose columns are the rows of AA. Whenever ABAB is defined,

(AB)T=BTAT.(AB)^T = B^TA^T.

The order reverses for a reason you can see in Problem 9. Entry (i,j)(i, j) of (AB)T(AB)^T is entry (j,i)(j, i) of ABAB, which is row jj of AA paired with column ii of BB. Row ii of BTB^T is column ii of BB, and column jj of ATA^T is row jj of AA, so BTATB^TA^T pairs the same two lists. On Day 16 the transpose lets you study the rows of AA as the columns of ATA^T, and from Day 34 on it carries symmetric matrices, dot products and least squares.

AA is 2×32 \times 3 and BB is 3×43 \times 4. Which product is defined?

Practice

Warm-up

AA is 4×64 \times 6 and ABAB is 4×24 \times 2. What size is BB? (Modeled on Lay §2.1 #7.)

Show the solution

For ABAB to be defined, BB needs as many rows as AA has columns, which is 66. The product has as many columns as BB, and the product has 22 columns. So BB is 6×26 \times 2.

Compute 2[3−102]−[14−25]2\begin{bmatrix} 3 & -1 \\ 0 & 2 \end{bmatrix} - \begin{bmatrix} 1 & 4 \\ -2 & 5 \end{bmatrix}, entering it row by row.

Show the solution
[6−204]−[14−25]=[5−62−1]\begin{bmatrix} 6 & -2 \\ 0 & 4 \end{bmatrix} - \begin{bmatrix} 1 & 4 \\ -2 & 5 \end{bmatrix} = \begin{bmatrix} 5 & -6 \\ 2 & -1 \end{bmatrix}

Write the transpose of [1−4023−5]\begin{bmatrix} 1 & -4 & 0 \\ 2 & 3 & -5 \end{bmatrix}, row by row.

Show the solution

The two rows become the two columns, so the transpose is 3×23 \times 2:

[12−430−5]\begin{bmatrix} 1 & 2 \\ -4 & 3 \\ 0 & -5 \end{bmatrix}

Core

Let A=[2−113]A = \begin{bmatrix} 2 & -1 \\ 1 & 3 \end{bmatrix} and B=[1024−11]B = \begin{bmatrix} 1 & 0 & 2 \\ 4 & -1 & 1 \end{bmatrix}. Find the third column of ABAB. (Modeled on Lay §2.1 #5.)

Show a hint

The third column of ABAB is AA times the third column of BB. Use its entries as weights on the columns of AA.

Show the solution

The third column of ABAB is Ab3A\mathbf b_3, a combination of the columns of AA with weights 22 and 11:

Ab3=2[21]+1[−13]=[35]A\mathbf b_3 = 2\begin{bmatrix} 2 \\ 1 \end{bmatrix} + 1\begin{bmatrix} -1 \\ 3 \end{bmatrix} = \begin{bmatrix} 3 \\ 5 \end{bmatrix}

The whole product is AB=[−21313−35]AB = \begin{bmatrix} -2 & 1 & 3 \\ 13 & -3 & 5 \end{bmatrix}. The product BABA is not defined, because BB has 3 columns and AA has 2 rows.

Let A=[3−2104−1]A = \begin{bmatrix} 3 & -2 & 1 \\ 0 & 4 & -1 \end{bmatrix} and B=[215−3−16]B = \begin{bmatrix} 2 & 1 \\ 5 & -3 \\ -1 & 6 \end{bmatrix}. Use the row–column rule to find (AB)12(AB)_{12} and (AB)21(AB)_{21}. (Modeled on Lay §2.1, Example 5.)

Show a hint

(AB)12(AB)_{12} pairs row 1 of AA with column 2 of BB. (AB)21(AB)_{21} pairs row 2 of AA with column 1 of BB.

Show the solution
(AB)12=3(1)+(−2)(−3)+1(6)=3+6+6=15(AB)21=0(2)+4(5)+(−1)(−1)=0+20+1=21\begin{aligned} (AB)_{12} &= 3(1) + (-2)(-3) + 1(6) = 3 + 6 + 6 = 15 \\ (AB)_{21} &= 0(2) + 4(5) + (-1)(-1) = 0 + 20 + 1 = 21 \end{aligned}

The full product is [−51521−18]\begin{bmatrix} -5 & 15 \\ 21 & -18 \end{bmatrix}.

Let R=[0−110]R = \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix} be the quarter turn and S=[1021]S = \begin{bmatrix} 1 & 0 \\ 2 & 1 \end{bmatrix} a vertical shear. Rotate first, then shear. Where does ȷ^\hat\jmath land? (Modeled on Lay §2.1, Example 7.)

Show a hint

Decide which product this is by asking which matrix touches the vector first. Then follow ȷ^\hat\jmath through one matrix at a time.

Show the solution

Rotating first and shearing second is the product SRSR, because the matrix next to x\mathbf x acts first. Follow ȷ^\hat\jmath through both steps:

Rȷ^=[−10],S(Rȷ^)=−1[12]+0[01]=[−1−2].\begin{aligned} R\hat\jmath &= \begin{bmatrix} -1 \\ 0 \end{bmatrix}, \\ S(R\hat\jmath) &= -1\begin{bmatrix} 1 \\ 2 \end{bmatrix} + 0\begin{bmatrix} 0 \\ 1 \end{bmatrix} = \begin{bmatrix} -1 \\ -2 \end{bmatrix}. \end{aligned}

So SR=[0−11−2]SR = \begin{bmatrix} 0 & -1 \\ 1 & -2 \end{bmatrix}. The other order gives RS=[−2−110]RS = \begin{bmatrix} -2 & -1 \\ 1 & 0 \end{bmatrix}, which sends ȷ^\hat\jmath to (−1,0)(-1, 0) instead.

Let A=[13−21]A = \begin{bmatrix} 1 & 3 \\ -2 & 1 \end{bmatrix} and B=[2k−42]B = \begin{bmatrix} 2 & k \\ -4 & 2 \end{bmatrix}. Find the value of kk that makes AB=BAAB = BA. (Modeled on Lay §2.1 #9.)

k=k =
Show a hint

Compute both products with kk left as a letter, then set matching entries equal.

Show the solution
AB=[2−12k+6−4−4−2k+2]=[−10k+6−82−2k]BA=[2−2k6+k−4−4−12+2]=[2−2kk+6−8−10]\begin{aligned} AB &= \begin{bmatrix} 2 - 12 & k + 6 \\ -4 - 4 & -2k + 2 \end{bmatrix} = \begin{bmatrix} -10 & k + 6 \\ -8 & 2 - 2k \end{bmatrix} \\ BA &= \begin{bmatrix} 2 - 2k & 6 + k \\ -4 - 4 & -12 + 2 \end{bmatrix} = \begin{bmatrix} 2 - 2k & k + 6 \\ -8 & -10 \end{bmatrix} \end{aligned}

The top-right and bottom-left entries already agree. The top-left entries need −10=2−2k-10 = 2 - 2k, so k=6k = 6, and the bottom-right entries give the same equation.

Let A=[102−2314−10]A = \begin{bmatrix} 1 & 0 & 2 \\ -2 & 3 & 1 \\ 4 & -1 & 0 \end{bmatrix} and B=[3−125−12]B = \begin{bmatrix} 3 & -1 \\ 2 & 5 \\ -1 & 2 \end{bmatrix}. Find the second row of ABAB without computing the other rows. (Modeled on Lay §2.1, Example 6.)

Show a hint

row2(AB)=row2(A) B\text{row}_2(AB) = \text{row}_2(A)\,B. Use the entries of row 2 of AA as weights on the rows of BB.

Show the solution

Row 2 of AA is (−2,3,1)(-2, 3, 1), so

row2(AB)=−2[3−1]+3[25]+1[−12]=[−6+6−12+15+2]=[−119].\begin{aligned} \text{row}_2(AB) &= -2\begin{bmatrix} 3 & -1 \end{bmatrix} + 3\begin{bmatrix} 2 & 5 \end{bmatrix} + 1\begin{bmatrix} -1 & 2 \end{bmatrix} \\ &= \begin{bmatrix} -6 + 6 - 1 & 2 + 15 + 2 \end{bmatrix} = \begin{bmatrix} -1 & 19 \end{bmatrix}. \end{aligned}

Challenge

Let A=[3−12041]A = \begin{bmatrix} 3 & -1 & 2 \\ 0 & 4 & 1 \end{bmatrix} and B=[12−205−3]B = \begin{bmatrix} 1 & 2 \\ -2 & 0 \\ 5 & -3 \end{bmatrix}. Find the first row of BTATB^TA^T without multiplying BTB^T by ATA^T. (Modeled on Lay §2.1 #33.)

Show a hint

BTATB^TA^T is the transpose of a product you can compute directly. Which part of ABAB becomes the first row after flipping?

Show the solution

BTAT=(AB)TB^TA^T = (AB)^T, so its first row is the first column of ABAB. By the row–column rule,

(AB)11=3(1)+(−1)(−2)+2(5)=15,(AB)21=0(1)+4(−2)+1(5)=−3.\begin{aligned} (AB)_{11} &= 3(1) + (-1)(-2) + 2(5) = 15, \\ (AB)_{21} &= 0(1) + 4(-2) + 1(5) = -3. \end{aligned}

The first row of BTATB^TA^T is [15−3]\begin{bmatrix} 15 & -3 \end{bmatrix}.

Let A=[1325]A = \begin{bmatrix} 1 & 3 \\ 2 & 5 \end{bmatrix}. The first column of ABAB is [47]\begin{bmatrix} 4 \\ 7 \end{bmatrix}. Find the first column of BB. (Modeled on Lay §2.1 #17.)

Show a hint

The first column of ABAB is Ab1A\mathbf b_1. Write b1=(p,q)\mathbf b_1 = (p, q) and match entries to get two equations.

Show the solution

We need p[12]+q[35]=[47]p\begin{bmatrix} 1 \\ 2 \end{bmatrix} + q\begin{bmatrix} 3 \\ 5 \end{bmatrix} = \begin{bmatrix} 4 \\ 7 \end{bmatrix}, which means p+3q=4p + 3q = 4 and 2p+5q=72p + 5q = 7. Doubling the first equation gives 2p+6q=82p + 6q = 8. Subtracting the second equation leaves q=1q = 1, and then p=4−3=1p = 4 - 3 = 1. So b1=(1,1)\mathbf b_1 = (1, 1).

Check: 1(1,2)+1(3,5)=(4,7)1(1, 2) + 1(3, 5) = (4, 7).

Let A=[1−2−24]A = \begin{bmatrix} 1 & -2 \\ -2 & 4 \end{bmatrix}, B=[3112]B = \begin{bmatrix} 3 & 1 \\ 1 & 2 \end{bmatrix} and C=[1504]C = \begin{bmatrix} 1 & 5 \\ 0 & 4 \end{bmatrix}. Compute ABAB and ACAC, entering ABAB row by row. Why can the two products agree when B≠CB \neq C? (Modeled on Lay §2.1 #10.)

Show a hint

Look at B−CB - C. What does AA do to each of its columns?

Show the solution
AB=[3−21−4−6+4−2+8]=[1−3−26]AC=[1−05−8−2+0−10+16]=[1−3−26]\begin{aligned} AB &= \begin{bmatrix} 3 - 2 & 1 - 4 \\ -6 + 4 & -2 + 8 \end{bmatrix} = \begin{bmatrix} 1 & -3 \\ -2 & 6 \end{bmatrix} \\ AC &= \begin{bmatrix} 1 - 0 & 5 - 8 \\ -2 + 0 & -10 + 16 \end{bmatrix} = \begin{bmatrix} 1 & -3 \\ -2 & 6 \end{bmatrix} \end{aligned}

The difference is B−C=[2−41−2]B - C = \begin{bmatrix} 2 & -4 \\ 1 & -2 \end{bmatrix}, and both of its columns are multiples of (2,1)(2, 1). Since A(2,1)=2(1,−2)+1(−2,4)=(0,0)A(2, 1) = 2(1, -2) + 1(-2, 4) = (0, 0), we get A(B−C)=0A(B - C) = 0, which means AB=ACAB = AC. The columns of AA lie on one line, so AA cannot tell BB and CC apart, and you cannot cancel AA.

Tomorrow, on Day 7, you ask whether a move can be undone, which means looking for a matrix A−1A^{-1} whose product with AA is the identity.