We already know how to multiply a matrix A by a single column vector x, and now we want to multiply A by a whole second matrix B.
1
Way 1: Mixing Columns
To find the product AB of two matrices, we start from how A multiplies a single column x: the numbers in x act as weights that tell us how much of each column of A to mix together.
[2314][13]=1[23]+3[14]=[23]+[312]=[515]
When we replace the single column x with a matrix B, we do that exact same column mix once for each column of B.
Way 1: Mixing Columns
Text solution
Mix the columns of A using Column 1 of BUse the weights 1 and 3 from the first column of B to build the first column of AB.
1[23]+3[14]=[23]+[312]=[515]
Mix the columns of A using Column 2 of BUse the weights 2 and 1 from the second column of B to build the second column of AB.
2[23]+1[14]=[46]+[14]=[510]
Put the resulting columns side by sidePlace the two output columns together in order to form AB.
[2314][1321]=[515510]
Reading the columns of the right-hand matrix as weights lets us do simple products in our head: in [2314][1002], the first column [10] copies Column 1 of A and the second column [02] doubles Column 2 of A.
Changing one column of B changes only the matching column of AB, while the other column of AB stays the same.
Each column of B works on its own, combining the fixed columns of A to build only its matching column of AB.
2
Way 2: Row by Column
When we only want a single entry of AB, such as the number in Row 7, Column 12 of a huge product, we don't need to build the whole column. We can find that one number directly from Row 7 of A and Column 12 of B.
Way 2: Row by Column
Text solution
Dot Row 1 of A with each column of B for the top rowMultiply the numbers in Row 1 of A by the matching numbers in each column of B and add them up.
Row 1, Column 1:[21][13]=(2×1)+(1×3)=2+3=5
Row 1, Column 2:[21][21]=(2×2)+(1×1)=4+1=5
Dot Row 2 of A with each column of B for the bottom rowMultiply the numbers in Row 2 of A by the matching numbers in each column of B and add them up.
Row 2, Column 1:[34][13]=(3×1)+(4×3)=3+12=15
Row 2, Column 2:[34][21]=(3×2)+(4×1)=6+4=10
Put each dot product in its matching row and columnPlace the four single numbers into their positions in AB.
[2314][1321]=[515510]
3
Way 3: Mixing Rows
Now suppose we want to build AB one entire row at a time, or apply a row operation like subtracting 3 times Row 1 from Row 2 across a whole matrix B. Instead of using the columns on the right as weights, we read the rows on the left as weights for mixing the rows of B.
Way 3: Mixing Rows
Text solution
Mix the rows of B using Row 1 of AUse the weights 2 and 1 from the top row of A to build the top row of AB.
2[12]+1[31]=[24]+[31]=[55]
Mix the rows of B using Row 2 of AUse the weights 3 and 4 from the bottom row of A to build the bottom row of AB.
3[12]+4[31]=[36]+[124]=[1510]
Stack the mixed rowsPut the resulting top and bottom rows together to form AB.
[2314][1321]=[515510]
When we multiply B on the left by [1−301], the top row [10] keeps Row 1 of B unchanged, and the bottom row [−31] subtracts 3 times Row 1 from Row 2:
Instead of building AB one column, one number, or one row at a time, we can see what each column of A contributes to the whole product at once by multiplying it by its matching row of B.
Way 4: Column by Row Layers
Text solution
Multiply Column 1 of A by Row 1 of B to form Layer 1Multiply Column 1 of A by the weights 1 and 2 in Row 1 of B to get the two columns of the first layer.
[23][12]=[1[23]2[23]]=[2346]
Multiply Column 2 of A by Row 2 of B to form Layer 2Multiply Column 2 of A by the weights 3 and 1 in Row 2 of B to get the two columns of the second layer.
[14][31]=[3[14]1[14]]=[31214]
Add the two layers togetherAdd the matching entries of Layer 1 and Layer 2 to get AB.
[2346]+[31214]=[515510]
In each layer, all the columns are multiples of one column of A and all the rows are multiples of one row of B, and adding the layers gives the same product AB.
Each column-and-row pair makes a full-size layer, and adding those layers in any order gives the same product as going column by column.
5
Matrix Sizes and When You Can Multiply
When A and B are not square, we need to check whether we can multiply them and find the size of AB before doing any arithmetic.
Matrix Sizes and When You Can Multiply
Writing the sizes of A and B side by side shows whether the columns and weights match up and what size the product will be:
(rows of Am×columns of An)×(rows of Bn×columns of Bp)⟶(size of ABm×p)
Text solution
Check that the inner numbers match and read the output sizeA has 2 columns and B has 2 rows, so the inner numbers match and the outer numbers give a 3×4 product.
(3×2)×(2×4)⟶3×4
Mix the 2 columns of A using each of the 4 columns of BEach column of B gives 2 weights to mix the 2 columns of A (each with 3 entries).
Put the 4 columns into the 3×4 productPlace the four resulting columns side by side.
120013[10210211]=120253026133
Each column of A pairs with one weight in every column of B, so AB is defined only when the number of columns of A matches the number of rows of B. The product AB gets its number of rows from A and its number of columns from B.
Because each column of B holds one weight for each column of A, their product works only when A has as many columns as B has rows, and it has as many rows as A and as many columns as B.
6
Why Order Matters: Usually AB=BA
With ordinary numbers, 3×5 is the same as 5×3. Now let's see what happens when we reverse the order of two matrices from AB to BA.
Why Order Matters: Usually AB ≠ BA
For our 3×2 matrix A and 2×4 matrix B, reversing the order to BA puts different inner numbers next to each other, so BA isn't even defined:
(2×columns of B4)×(rows of A3×2)⟶4=3 (undefined)
Even when both matrices are 2×2 so both products are defined, reversing AB to BA swaps which matrix gives the columns and which gives the weights.
Text solution
Mix the columns of B using Column 1 of AWith B now on the left, use the weights 2 and 3 from the first column of A to mix the columns of B.
2[13]+3[21]=[26]+[63]=[89]
Mix the columns of B using Column 2 of AUse the weights 1 and 4 from the second column of A to mix the columns of B.
1[13]+4[21]=[13]+[84]=[97]
Compare BA with ABPut the columns of BA side by side to see that swapping the order changes the product.
BA=[1321][2314]=[8997]=[515510]=AB
7
When Columns Cancel: AB=0 and AB=AC
With ordinary numbers, ab=0 means a=0 or b=0, and 5x=5y lets us cancel the 5 to get x=y. With matrices, let's see how AB=0 can happen when neither A nor B has any zeros, and why AB=AC does not let us automatically cancel A to get B=C.
When Columns Cancel: AB = 0 and AB = AC
Text solution
Pick weights that cancel the columns of A to zeroBecause Column 2 of A=[1224] is 2 times Column 1, taking 2 of Column 1 and −1 of Column 2 (or −4 of Column 1 and 2 of Column 2) cancels them out to [00].
Mix the columns of A with two different weight matrices B and CTrading 2 of Column 1 for 1 of Column 2 keeps the mix the same, so B=[3140] and C=[1202] give the exact same product.
AB=[3[12]+1[24]4[12]+0[24]]=[51048]
AC=[1[12]+2[24]0[12]+2[24]]=[51048]
When the two columns of A lie on the same line, there is a whole line of nonzero weight pairs that cancel them to [00], and each parallel line of weight pairs gives different weights that all produce the exact same output column.
When both columns lie on the same line, a whole line of different weight pairs gives the exact same output, including nonzero weights that cancel the columns to zero.
Key concepts
Whenever you see a matrix product AB=C, start with the sizes (m×n)(n×p)⟶m×p: the inner numbers n must match so each column of B has one weight for each column of A, and the outer numbers m×p give the size of C. For example, (3×2)(2×4) gives a 3×4 matrix, whereas (2×4)(3×2) is undefined because 4=3.
Once the sizes match, pick the way of multiplying that fits what you need:
Multiply on the right to mix columns (Way 1: A×Column of B)
Use this to see what AB is doing overall or when the right-hand matrix has simple columns, building C one column at a time:
[2314][13]=1[23]+3[14]=[515]
Dot a row with a column for a single entry (Way 2: Row of A⋅Column of B)
Don't multiply the full matrices if you only need one entry. For Row 2, Column 1 of AB, just dot Row 2 of A with Column 1 of B:
[34][13]=(3×1)+(4×3)=15
Multiply on the left to mix rows (Way 3: Row of A×B)
Use this when a matrix on the left does row operations on B, building C one row at a time:
[−31][1321]=−3[12]+1[31]=[0−5]
Multiply Column by Row for full-size layers (Way 4: Column k of A×Row k of B)
Use this to break AB into simple layers where each column of A is multiplied by the weights in its matching row of B:
Never swap AB to BA, because reversing the order swaps the columns with the weights. And when A's columns can cancel each other out, as in A=[1224] where 2[12]−1[24]=[00], do not assume AB=0 means A=0 or B=0, and do not cancel A from AB=AC to get B=C.
8
Practice
1
Let A=3−10124 and B=[2−103]. By mixing the columns of A, write each column of AB as a combination of the columns of A and find AB.
Take the weights from the columns of B, not its rows. Using the top row [20] and bottom row [−13] as weights is a common mistake and gives 6−200712.
Read the two numbers in Column 1 of B as the weights for Column 1 and Column 2 of A. What weights does Column 2 of B give?
Take the weights from the columns of B, not its rows. Using the top row [20] and bottom row [−13] as weights is a common mistake and gives 6−200712.
Let A=401−13−2256 and B=23−2701−145. Without computing the full product, find the single entry in Row 3, Column 2 of AB.
Take Row 3 from the left matrix A and Column 2 from the right matrix B. Swapping them to Row 2 of A and Column 3 of B finds the entry in Row 2, Column 3 instead and gives 37.
Which single row of A and single column of B give the entry in Row 3, Column 2?
Take Row 3 from the left matrix A and Column 2 from the right matrix B. Swapping them to Row 2 of A and Column 3 of B finds the entry in Row 2, Column 3 instead and gives 37.
[1−26]701=(1×7)+(−2×0)+(6×1)=7+0+6=13
3
Let B=[24−113−2]. Find the 2×2 matrix E that multiplies B on the left to keep Row 1 the same and subtract 2 times Row 1 from Row 2, then compute EB.
Each row of E gives the weights [weight on Row 1weight on Row 2] for mixing the rows of B.
Put the weights for the new Row 2 across the bottom row of E as [−21]. Putting −2 in the top-right as [10−21] changes Row 1 instead and gives [−64−317−2].
E=[1−201]
Row 1 of EB:1[2−13]+0[41−2]=[2−13]
In the last entry of Row 2, watch the negative signs when subtracting 2(3) from −2. Adding 6 instead of subtracting gives 4 instead of −8.
Row 2 of EB:−2[2−13]+1[41−2]=[−42−6]+[41−2]=[03−8]
EB=[20−133−8]
4
Break the product AB=[21−13][321−2] into Layer 1 (Column 1 of A×Row 1 of B) and Layer 2 (Column 2 of A×Row 2 of B), then add the two layers to find AB.
For Layer 2, be sure to pair Column 2 of A with Row 2 of B ([2−2]). Using Column 2 of B ([1−2]) as [1−2] instead gives [−132−6] and leads to the wrong sum [564−5].
Multiply each 2×1 column of A by its matching 1×2 row of B so each pair gives a 2×2 matrix.
Layer 1:[21][31]=[6321]
For Layer 2, be sure to pair Column 2 of A with Row 2 of B ([2−2]). Using Column 2 of B ([1−2]) as [1−2] instead gives [−132−6] and leads to the wrong sum [564−5].
Layer 2:[−13][2−2]=[−262−6]
AB=[6321]+[−262−6]=[494−5]
5
Let A=[2−14] (1×3), B=321 (3×1), and C=[1205] (2×2). Find which of the products AB,BA, and AC are defined, give their sizes, and compute them.
Write the sizes next to each other as (m×n)×(n×p) for each pair: do the two inner numbers match, and what are the two outer numbers?
For AB, the sizes are (1×3)×(3×1), so the inner 3s match and AB is 1×1:
AB=[2−14]321=[(2×3)+(−1×2)+(4×1)]=[8]
For BA, the sizes are (3×1)×(1×3). Don't assume BA is the same 1×1 matrix [8] as AB: the inner 1s match and the outer numbers show that multiplying a 3×1 column by a 1×3 row gives a 3×3 layer matrix:
BA=321[2−14]=642−3−2−11284
For AC, the sizes are (1×3)×(2×2); the inner numbers 3 and 2 do not match, so AC is undefined.
6
Let A=[31−6−2]. By mixing the columns of A, find a 2×2 matrix B with no zero entries and two different columns such that AB=[0000].
How is Column 2 of A related to Column 1 of A, and what pair of nonzero weights makes them cancel to [00]?
Column 2 of A is −2 times Column 1, so we need 2 of Column 1 for every 1 of Column 2. Put those cancelling weights into the columns of B, not the rows. Putting [21] and [−4−2] in the rows of B gives [3010155] instead of zeros.
2[31]+1[−6−2]−4[31]−2[−6−2]=[00],=[00]
B=[21−4−2]
7
Let A=[1236] and B=[4112]. Find a 2×2 matrix C that has no entries in common with B in the same spots such that AB=AC, and find their product with A.
Adding [13] instead of trading 3 for −1 is a common mistake and changes the first column to [1734].
Since Column 2 of A is 3 times Column 1 of A, trading 3 of Column 1 for 1 of Column 2 leaves the mix unchanged.
First find the mix produced by each column of B:
AB=[4[12]+1[36]1[12]+2[36]]=[714714]
Because 3[12]−1[36]=[00], we can subtract 3 from the top weight and add 1 to the bottom weight (or add 3 to the top weight and subtract 1 from the bottom weight) without changing the output. Adding [13] instead of trading 3 for −1 is a common mistake and changes the first column to [1734].