Multiplying Two Matrices
How to multiply two matrices: a row times a column, when a product can be found and what its order is, row by column for every element, why AB and BA differ, squares, and unknowns in a product.
Before you start
You will multiply many negative numbers (Secondary 1): , .
In lesson 4.3 every element of a matrix was multiplied by the same number, as below. Multiplying two matrices is different: the rows of the first meet the columns of the second.
| 3 | −1 | ||
| 0 | 4 |
| 6 | −2 | ||
| 0 | 8 |
A Row Times a Column
At the food stall of lesson 4.1, mee rebus costs $4, nasi lemak $3 and mee soto $5. A family buys 3 plates of mee rebus, 2 of nasi lemak and 1 of mee soto. Their meal costs dollars: each number of plates times its price, then added.
With the plates as a row matrix and the prices as a column matrix, this is how a row is multiplied by a column: first element times first element, second times second, third times third, and the products added. The answer is a matrix.
A row times a column
Multiply the elements in pairs, first with first, second with second, and so on, and add the products.
The row and the column must have the same number of elements.
The answer is a matrix of order , written in brackets, such as (23).
Example 1: The Cost of a Meal
Work out the product of the row of plates and the column of prices, and say what it means.
| 3 | 2 | 1 |
| 4 | ||
| 3 | ||
| 5 |
Solution
Pair the elements, first with first, second with second, third with third; multiply, then add:
| 3 | 2 | 1 |
| 4 | ||
| 3 | ||
| 5 |
| 3 × 4 + 2 × 3 + 1 × 5 |
| 12 + 6 + 5 |
| 23 |
The plates are counted and the prices are in dollars, so the answer is the cost of the meal in dollars.
The product is the matrix (23): the meal costs $23.
When Can Two Matrices Be Multiplied?
To multiply two matrices, each row of the first is multiplied by each column of the second, as above. So a row of the first must have as many elements as a column of the second: the number of columns of the first must equal the number of rows of the second.
When a product can be found, and its order
Write the two orders side by side. For a matrix times a matrix: .
The inner numbers (3 and 3) must be equal; if they are not, the product cannot be found.
The outer numbers (2 and 2) give the order of the product: .
In short: gives .
Example 2: Which Products Can Be Found?
A is a matrix, B is and C is . Which of AB, BA, AC, CA, BC and CB can be found? Give the order of each one that can.
Solution
AB: . The inner numbers 3 and 3 agree, so AB can be found; its order is .
BA: . 2 and 2 agree; the order is .
AC: . 3 and 2 differ, so AC cannot be found. (Some books say AC does not exist, or is not defined.)
CA: . 2 and 2 agree; the order is .
BC: . 2 and 2 agree; the order is .
CB: . 2 and 3 differ: CB cannot be found.
AB , BA , CA , BC ; AC and CB cannot be found.
Row by Column
The elements of a product
The element in row 2, column 1 of AB comes from row 2 of A and column 1 of B: multiply that row by that column, as in Example 1.
In the same way, every element of AB is a row of A times a column of B. Work out one element at a time, and write the working inside the brackets.
AB means A first, then B: the rows come from A, the columns from B.
Example 3: Two 2 × 2 Matrices
Find AB.
| 2 | 1 | ||
| 3 | −1 |
| 4 | 0 | ||
| −2 | 5 |
Solution
: the product can be found and is .
Row 1, column 1: row 1 of A is 2, 1 and column 1 of B is 4, −2:
Row 1, column 2: 2, 1 with 0, 5: . Row 2 of A is 3, −1; with column 1: with column 2:
All four inside the brackets:
| 2 × 4 + 1 × (−2) | 2 × 0 + 1 × 5 | ||
| 3 × 4 + (−1) × (−2) | 3 × 0 + (−1) × 5 |
| 8 − 2 | 0 + 5 | ||
| 12 + 2 | 0 − 5 |
| 6 | 5 | ||
| 14 | −5 |
The product:
| 6 | 5 | ||
| 14 | −5 |
Example 4: A 2 × 3 Matrix Times a 3 × 2 Matrix
Find PQ.
| 1 | 2 | 0 | ||
| 3 | −1 | 4 |
| 2 | 1 | ||
| 0 | 3 | ||
| 5 | −2 |
Solution
: the inner numbers agree, and PQ is . Each element is a row of three elements times a column of three.
| 1 × 2 + 2 × 0 + 0 × 5 | 1 × 1 + 2 × 3 + 0 × (−2) | ||
| 3 × 2 + (−1) × 0 + 4 × 5 | 3 × 1 + (−1) × 3 + 4 × (−2) |
| 2 + 0 + 0 | 1 + 6 + 0 | ||
| 6 + 0 + 20 | 3 − 3 − 8 |
| 2 | 7 | ||
| 26 | −8 |
Row 2, column 2, for example: row 2 of P is 3, −1, 4 and column 2 of Q is 1, 3, −2: .
A matrix:
| 2 | 7 | ||
| 26 | −8 |
AB and BA Are Not the Same
Numbers can be multiplied either way round: (Secondary 1). Matrices cannot. In general AB ≠ BA: one may be found and the other not (Example 2), the two may have different orders, or both may be and still be different.
So always multiply the matrices the way round they are written: AB is A first, then B.
Example 5: The Other Way Round
With the matrices of Examples 3 and 4, find (a) BA, and compare it with AB; (b) QP, and compare it with PQ.
Solution
(a) Now the rows come from B and the columns from A:
| 4 × 2 + 0 × 3 | 4 × 1 + 0 × (−1) | ||
| (−2) × 2 + 5 × 3 | (−2) × 1 + 5 × (−1) |
| 8 | 4 | ||
| 11 | −7 |
AB and BA are both , but their elements differ.
(b) : QP is . Each element is a row of two elements of Q times a column of two of P:
| 2 × 1 + 1 × 3 | 2 × 2 + 1 × (−1) | 2 × 0 + 1 × 4 | ||
| 0 × 1 + 3 × 3 | 0 × 2 + 3 × (−1) | 0 × 0 + 3 × 4 | ||
| 5 × 1 + (−2) × 3 | 5 × 2 + (−2) × (−1) | 5 × 0 + (−2) × 4 |
| 5 | 3 | 4 | ||
| 9 | −3 | 12 | ||
| −1 | 12 | −8 |
PQ is but QP is : they do not even have the same order.
AB ≠ BA, and PQ and QP have different orders.
| 8 | 4 | ||
| 11 | −7 |
| 5 | 3 | 4 | ||
| 9 | −3 | 12 | ||
| −1 | 12 | −8 |
The Square of a Matrix
A²
means AA: the matrix multiplied by itself, row by column.
It can be found only for a square matrix: a matrix has no square, as cannot be found.
It is not found by squaring each element.
Example 6: A Square
With A from Example 3, find . Can be found, for P from Example 4?
| 2 | 1 | ||
| 3 | −1 |
Solution
| 2 | 1 | ||
| 3 | −1 |
| 2 | 1 | ||
| 3 | −1 |
| 2 × 2 + 1 × 3 | 2 × 1 + 1 × (−1) | ||
| 3 × 2 + (−1) × 3 | 3 × 1 + (−1) × (−1) |
| 7 | 1 | ||
| 3 | 4 |
Squaring each element would give 4, 1 in row 1 and 9, 1 in row 2, which is wrong:
| 4 | 1 | ||
| 9 | 1 |
P is , not square:
cannot be found.
| 7 | 1 | ||
| 3 | 4 |
Unknowns in a Product
Multiply out the product, element by element, with the unknowns in it. Then equate corresponding elements and solve, starting with an equation that has only one unknown.
Example 7: Two Unknowns
Find and .
| 2 | x | ||
| 1 | 3 |
| 4 | ||
| y |
| 14 | ||
| 13 |
Solution
gives a matrix:
| 2 | x | ||
| 1 | 3 |
| 4 | ||
| y |
| 2 × 4 + x × y | ||
| 1 × 4 + 3 × y |
| xy + 8 | ||
| 3y + 4 |
| 14 | ||
| 13 |
Row 2 has one unknown: , so and .
Row 1: , so . With : and .
Check: and .
,
Common Mistakes
- Multiplying corresponding elements, as in a sum. A product is rows of the first times columns of the second.
- Giving the wrong order to the product: is , from the outer numbers.
- Taking a column of the first matrix with a row of the second.
- Losing a sign in a long row:
- Treating AB and BA as equal, or working out BA when AB is asked.
- Squaring each element for . .
Practice
Try each question before you open its solution. Questions 5 and 12 are word problems.
Question 1
Say whether each product can be found, and if so give its order. The orders of the two matrices are (a) (b) (c) (d) (e) (f)
ShowHide solution
(a) 3 and 3 agree: . (b) 1 and 1 agree: . (c) 3 and 3 agree: .
(d) 2 and 3 differ: cannot be found. (e) 2 and 2 agree: . (f) 2 and 1 differ: cannot be found.
(a) (b) (c) (d) cannot be found (e) (f) cannot be found
Question 2
Work out the product.
| 1 | −2 | ||
| 3 | 0 |
| 5 | ||
| 2 |
ShowHide solution
gives :
| 1 | −2 | ||
| 3 | 0 |
| 5 | ||
| 2 |
| 1 × 5 + (−2) × 2 | ||
| 3 × 5 + 0 × 2 |
| 5 − 4 | ||
| 15 + 0 |
| 1 | ||
| 15 |
A matrix:
| 1 | −2 | ||
| 3 | 0 |
| 5 | ||
| 2 |
| 1 | ||
| 15 |
Question 3
Work out the product.
| 2 | 0 | −1 |
| 3 | 1 | ||
| 4 | −2 | ||
| 1 | 5 |
ShowHide solution
gives : the row times each column in turn.
| 2 | 0 | −1 |
| 3 | 1 | ||
| 4 | −2 | ||
| 1 | 5 |
| 2 × 3 + 0 × 4 + (−1) × 1 | 2 × 1 + 0 × (−2) + (−1) × 5 |
| 6 + 0 − 1 | 2 + 0 − 5 |
| 5 | −3 |
A matrix:
| 2 | 0 | −1 |
| 3 | 1 | ||
| 4 | −2 | ||
| 1 | 5 |
| 5 | −3 |
Question 4
Work out the product of the column and the row.
| 2 | ||
| 3 |
| 1 | 4 |
ShowHide solution
: the inner numbers 1 and 1 agree, and the product is . Each "row times column" is a single pair:
| 2 | ||
| 3 |
| 1 | 4 |
| 2 × 1 | 2 × 4 | ||
| 3 × 1 | 3 × 4 |
| 2 | 8 | ||
| 3 | 12 |
A matrix:
| 2 | ||
| 3 |
| 1 | 4 |
| 2 | 8 | ||
| 3 | 12 |
Question 5
The matrix G gives the goals scored by three players (rows) in two matches (columns). Work out (1 1 1)G and say what it gives.
| match 1 | match 2 | |||
|---|---|---|---|---|
| Daniel | 4 | 2 | ||
| Farid | 3 | 5 | ||
| Kumar | 1 | 6 |
ShowHide solution
gives :
| 1 | 1 | 1 |
| 1 × 4 + 1 × 3 + 1 × 1 | 1 × 2 + 1 × 5 + 1 × 6 |
| 8 | 13 |
Multiplying by 1 changes nothing, so a row of ones adds the elements of each column: the three players scored 8 goals in match 1 and 13 goals in match 2.
The goals the three players scored in each match: 8 in match 1, 13 in match 2.
Question 6
Find NK and KN. What does multiplying by K do in each case?
| 1 | 2 | ||
| 3 | 4 |
| 0 | 1 | ||
| 1 | 0 |
ShowHide solution
| 1 × 0 + 2 × 1 | 1 × 1 + 2 × 0 | ||
| 3 × 0 + 4 × 1 | 3 × 1 + 4 × 0 |
| 2 | 1 | ||
| 4 | 3 |
| 0 × 1 + 1 × 3 | 0 × 2 + 1 × 4 | ||
| 1 × 1 + 0 × 3 | 1 × 2 + 0 × 4 |
| 3 | 4 | ||
| 1 | 2 |
NK is N with its two columns swapped; KN is N with its two rows swapped. NK ≠ KN.
NK swaps the columns of N; KN swaps its rows.
| 2 | 1 | ||
| 4 | 3 |
| 3 | 4 | ||
| 1 | 2 |
Question 7
Find .
| 1 | 2 | ||
| 0 | 3 |
ShowHide solution
| 1 | 2 | ||
| 0 | 3 |
| 1 | 2 | ||
| 0 | 3 |
| 1 × 1 + 2 × 0 | 1 × 2 + 2 × 3 | ||
| 0 × 1 + 3 × 0 | 0 × 2 + 3 × 3 |
| 1 | 8 | ||
| 0 | 9 |
Row 1, column 2 is , not .
Row by column:
| 1 | 8 | ||
| 0 | 9 |
Question 8
Find .
| x | 1 | ||
| 2 | 3 |
| 2 | ||
| 5 |
| 13 | ||
| 19 |
ShowHide solution
| x | 1 | ||
| 2 | 3 |
| 2 | ||
| 5 |
| x × 2 + 1 × 5 | ||
| 2 × 2 + 3 × 5 |
| 2x + 5 | ||
| 19 |
| 13 | ||
| 19 |
Row 1: , so and . Row 2 has no unknown: , which agrees.
Question 9
Find the possible values of .
| x | 3 |
| x | ||
| 4 |
| 16 |
ShowHide solution
| x | 3 |
| x | ||
| 4 |
| x × x + 3 × 4 |
| x2 + 12 |
| 16 |
, so and or .
Both work: and Keep both.
or
Question 10
True or false: "If AB can be found, then BA can be found." Use the matrices A and B below to decide.
| 1 | 2 | 0 | ||
| 0 | 1 | 3 |
| 1 | ||
| 2 | ||
| 1 |
ShowHide solution
AB is : it can be found, and is .
| 1 × 1 + 2 × 2 + 0 × 1 | ||
| 0 × 1 + 1 × 2 + 3 × 1 |
| 1 + 4 + 0 | ||
| 0 + 2 + 3 |
| 5 | ||
| 5 |
BA is :
False: here AB can be found but BA cannot.
Question 11
With A and B from Example 3: (a) Hui Min works out AB by multiplying corresponding elements, and gets 8, 0 in row 1 and −6, −5 in row 2. (b) Amir finds the square of the matrix M below by squaring each element. Explain each mistake and give the right answers.
| 2 | −1 | ||
| 1 | 0 |
ShowHide solution
(a) A product is not found element by element: each element of AB is a row of A times a column of B. The right answer is Example 3's:
| 6 | 5 | ||
| 14 | −5 |
(b) means MM, row by column:
| 2 | −1 | ||
| 1 | 0 |
| 2 | −1 | ||
| 1 | 0 |
| 2 × 2 + (−1) × 1 | 2 × (−1) + (−1) × 0 | ||
| 1 × 2 + 0 × 1 | 1 × (−1) + 0 × 0 |
| 3 | −2 | ||
| 2 | −1 |
Amir's answer, 4, 1 in row 1 and 1, 0 in row 2, is the elements squared, which is not .
(a) AB is rows times columns. (b) :
| 6 | 5 | ||
| 14 | −5 |
| 3 | −2 | ||
| 2 | −1 |
Question 12
At the food stall (mee rebus $4, nasi lemak $3, mee soto $5), Aisyah buys 2 plates of mee rebus and 1 of nasi lemak, and Ben buys 1 mee rebus, 2 nasi lemak and 1 mee soto. Write what they buy as a matrix R and the prices as a column matrix C, and use a product to find what each of them pays.
ShowHide solution
Rows of R: Aisyah, Ben; columns: the three dishes, in the same sequence as the rows of C.
| mee rebus | nasi lemak | mee soto | |||
|---|---|---|---|---|---|
| Aisyah | 2 | 1 | 0 | ||
| Ben | 1 | 2 | 1 |
| 4 | ||
| 3 | ||
| 5 |
| 2 × 4 + 1 × 3 + 0 × 5 | ||
| 1 × 4 + 2 × 3 + 1 × 5 |
| 8 + 3 + 0 | ||
| 4 + 6 + 5 |
| 11 | ||
| 15 |
Aisyah pays $11 and Ben $15.
Aisyah $11, Ben $15
Key Points
- A row times a column: multiply in pairs and add. The row and the column must have the same number of elements.
- A product can be found only when the columns of the first equal the rows of the second: , inner numbers equal; the outer numbers give the order, .
- The element in row 2, column 1 of AB is row 2 of A times column 1 of B.
- In general AB ≠ BA: keep the matrices the way round they are written.
- , for a square matrix only; never square each element.
- For unknowns, multiply out, equate corresponding elements, and solve.