- Learn how to multiply matrices
How to Multiply Matrices
Matrix Multiplication
When we turn to matrix multiplication, which means multiplying one matrix by another, the process DOES NOT follow the same logic we used when multiplying a matrix by a scalar. We DO NOT multiply matrices by multiplying the corresponding elements. Matrix multiplication is performed using a row-by-column multiplication. Let's start with a simple example. $$A=\left[\begin{array}{cc}-5&1\\ -1&-3\\3 & 4\end{array}\right]$$ $$B=\left[\begin{array}{cc}0&-2\\ 3&6\end{array}\right]$$ Let's find the product matrix AB. $$AB = \left[\begin{array}{cc}-5&1\\ -1&-3\\3 & 4\end{array}\right] \left[\begin{array}{cc}0&-2\\ 3&6\end{array}\right] = \left[\begin{array}{cc}\_&\_\\ \_&\_\\ \_ & \_\end{array}\right]$$ The setup for AB shows that we will end up with a 3 × 2 matrix for our product. We will get to where the 3 × 2 comes from later on in the tutorial. For now, let's go through the basics of the process.We will begin by multiplying each element of row 1 in our matrix A by the corresponding element of column 1 in our matrix B. We will then find the sum of all the products and place the result in the (row 1, col 1) position of the product. $$-5 \cdot 0 + 1 \cdot 3 = 0 + 3 = 3$$ Notice what we mean by multiplying corresponding elements here. The (-5) is the first element of row 1 in matrix A, and this is multiplied by 0, which is the first element of column 1 in matrix B. Similarly, the 1 is the second element of row 1 in matrix A, and this is multiplied by 3, which is the second element of column 1 in matrix B. Then we find the sum of the products, which gives us 3. Since the multiplication involved row 1 of matrix A and column 1 of matrix B, the sum is placed in (row 1, col 1) of the product. Let's update our product matrix AB. $$AB = \left[\begin{array}{cc}-5&1\\ -1&-3\\3 & 4\end{array}\right] \left[\begin{array}{cc}0&-2\\ 3&6\end{array}\right] = \left[\begin{array}{cc}3&\_\\ \_&\_\\ \_ & \_\end{array}\right]$$ Now, we will use the same logic to find the remaining elements of our product matrix AB. For the position of (row 2, col 1), we will use row 2 of matrix A and column 1 of matrix B. $$-1 \cdot 0 + -3 \cdot 3 = 0 - 9 = -9$$ Let's update our product matrix AB. $$AB = \left[\begin{array}{cc}-5&1\\ -1&-3\\3 & 4\end{array}\right] \left[\begin{array}{cc}0&-2\\ 3&6\end{array}\right] = \left[\begin{array}{cc}3&\_\\ -9&\_\\ \_ & \_\end{array}\right]$$ For the position of (row 3, col 1), we will use row 3 of matrix A and column 1 of matrix B. $$3 \cdot 0 + 4 \cdot 3 = 0 + 12 = 12$$ Let's update our product matrix AB. $$AB = \left[\begin{array}{cc}-5&1\\ -1&-3\\3 & 4\end{array}\right] \left[\begin{array}{cc}0&-2\\ 3&6\end{array}\right] = \left[\begin{array}{cc}3&\_\\ -9&\_\\ 12 & \_\end{array}\right]$$ At this point, we will now start working on the second column of our product matrix AB. For the position of (row 1, col 2), we will use row 1 of matrix A and column 2 of matrix B. $$-5 \cdot -2 + 1 \cdot 6 = 10 + 6 = 16$$ Let's update our product matrix AB. $$AB = \left[\begin{array}{cc}-5&1\\ -1&-3\\3 & 4\end{array}\right] \left[\begin{array}{cc}0&-2\\ 3&6\end{array}\right] = \left[\begin{array}{cc}3&16 \\ -9&\_\\ 12 & \_\end{array}\right]$$ For the position of (row 2, col 2), we will use row 2 of matrix A and column 2 of matrix B. $$-1 \cdot -2 + -3 \cdot 6 = 2 - 18 = -16$$ Let's update our product matrix AB. $$AB = \left[\begin{array}{cc}-5&1\\ -1&-3\\3 & 4\end{array}\right] \left[\begin{array}{cc}0&-2\\ 3&6\end{array}\right] = \left[\begin{array}{cc}3&16 \\ -9& -16 \\ 12 & \_\end{array}\right]$$ For the final position of (row 3, col 2), we will use row 3 of matrix A and column 2 of matrix B. $$3 \cdot -2 + 4 \cdot 6 = -6 + 24 = 18$$ Let's update our product matrix AB. $$AB = \left[\begin{array}{cc}-5&1\\ -1&-3\\3 & 4\end{array}\right] \left[\begin{array}{cc}0&-2\\ 3&6\end{array}\right] = \left[\begin{array}{cc}3&16 \\ -9& -16 \\ 12 & 18\end{array}\right]$$
Definition of Matrix Multiplication
As we saw in our example above, we found our product matrix AB using a row-by-column multiplication. This means we are working with rows of the first matrix (leftmost) and columns of the second matrix (rightmost). The product of an m × n matrix, A, and an n × p matrix, B, is an m × p matrix, AB. To find the element in the position of (row i, col j) in our product matrix AB, we multiply each element in row i of matrix A by the corresponding element in column j of matrix B and add the products. \[ A = \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ \colorbox{yellow}{$a_{i1}$} & \colorbox{cyan}{$a_{i2}$} & \cdots & \colorbox{lime}{$a_{in}$} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{bmatrix} \] \[ B = \begin{bmatrix} b_{11} & \cdots & \colorbox{yellow}{$b_{1j}$} & \cdots & b_{1p} \\ b_{21} & \cdots & \colorbox{cyan}{$b_{2j}$} & \cdots & b_{2p} \\ \vdots & \ddots & \vdots & \ddots & \vdots \\ b_{n1} & \cdots & \colorbox{lime}{$b_{nj}$} & \cdots & b_{np} \end{bmatrix} \] If we let C = AB, then the element cij is found as: $$c_{ij} = a_{i1} \cdot b_{1j} + a_{i2} \cdot b_{2j} + \cdots + a_{in} \cdot b_{nj}$$ As we alluded to above, before we attempt to perform our matrix multiplication, the number of columns in the first matrix (leftmost) must be equal to the number of rows in the second matrix (rightmost). If this is not the case, we can say the product of the two matrices is undefined or it doesn't exist.Why Must the Columns of Matrix A Equal the Rows of Matrix B?
Let's stop and think for a moment about why the columns of matrix A need to be equal to the rows of matrix B.Properties of Matrix Multiplication
We will note here that matrix multiplication is not commutative, which means the order in which we multiply matrices does matter. In general, we can say that AB ≠ BA. We will see an example that proves this later on. For now, let's look at some properties of matrix multiplication. For our list, we will assume that A, B, and C are matrices and k is a scalar. We will also assume that the order of each matrix allows all of our operations listed to be defined.- (AB)C = A(BC)
- Associative property of matrix multiplication
- A(B + C) = AB + AC
- Distributive property of matrix multiplication
- k(AB) = (kA)B
- Associative property of scalar multiplication
Example #1: Find AB. $$A = \left[\begin{array}{cc}0&3\\ -1&2\\3 & 3\end{array}\right]$$ $$B = \left[\begin{array}{cc}-3&0\\ -3&6\\-4 & -2\end{array}\right]$$ Since our matrix A is a 3 × 2 and our matrix B is also a 3 × 2, the product matrix AB does not exist. Again, the number of columns in the first matrix (there are 2 columns in matrix A) must be equal to the number of rows in the second matrix (there are 3 rows in matrix B). Notice that if you try to multiply any row of matrix A by any column of matrix B, you won't have enough corresponding elements to perform the multiplication. Each row of matrix A has exactly 2 elements (given the fact that matrix A is a 2-column matrix) and each column of matrix B has exactly 3 elements (given the fact that matrix B is a 3-row matrix). Note: We can also say the product of the two matrices is undefined or not possible. The exact wording of how to deal with this situation will depend on the textbook or resource you are using.
Example #2: Find AB and BA. $$A = \left[\begin{array}{ccc}9&4 & -8\end{array}\right]$$ $$B = \left[\begin{array}{c}1 \\ -2 \\ 7\end{array}\right]$$ Let's start with the product matrix AB. A is a 1 × 3 matrix (number of columns is 3) and B is a 3 × 1 matrix (number of rows is 3). Since the number of columns in matrix A is equal to the number of rows in matrix B, we can perform the multiplication. Our product will be a 1 × 1 matrix. This comes from the number of rows from matrix A, which is 1, and the number of columns from matrix B, which is also 1. $$AB = \left[\begin{array}{ccc}9&4 & -8\end{array}\right] \left[\begin{array}{c}1 \\ -2 \\ 7\end{array}\right] = \left[\begin{array}{c}\_\end{array}\right]$$ To find our single-element product matrix AB, we will multiply every element of row 1 from matrix A by each corresponding element of column 1 from matrix B and then add all the products. $$9 \cdot 1 + 4 \cdot -2 + -8 \cdot 7 = 9 - 8 - 56 = 1 - 56 = -55$$ $$AB = \left[\begin{array}{ccc}9&4 & -8\end{array}\right] \left[\begin{array}{c}1 \\ -2 \\ 7\end{array}\right] = \left[\begin{array}{c}-55\end{array}\right]$$ Now, let's think about the product matrix BA. B is a 3 × 1 matrix (number of columns is 1) and A is a 1 × 3 matrix (number of rows is 1). Since the number of columns in matrix B is equal to the number of rows in matrix A, we can perform the multiplication. Our product will now be a 3 × 3 matrix. This comes from the number of rows from matrix B, which is 3, and the number of columns from matrix A, which is also 3. $$BA = \left[\begin{array}{c}1 \\ -2 \\ 7\end{array}\right] \left[\begin{array}{ccc}9&4 & -8\end{array}\right] = \left[\begin{array}{ccc}\_ & \_ & \_ \\ \_ & \_ & \_ \\ \_ & \_ & \_ \end{array}\right]$$ To find the product, think about each element in the product matrix BA. For the position of (row 1, col 1), we use the first row of matrix B and the first column of matrix A. Then for the position of (row 1, col 2), we will use the first row of matrix B and the second column of matrix A. We will continue with this pattern to fill in all elements of the product matrix BA. $$BA = \left[\begin{array}{c}1 \\ -2 \\ 7\end{array}\right] \left[\begin{array}{ccc}9&4 & -8\end{array}\right] = \left[\begin{array}{ccc}1 \cdot 9 & 1 \cdot 4 & 1 \cdot -8 \\ -2 \cdot 9 & -2 \cdot 4 & -2 \cdot -8 \\ 7 \cdot 9 & 7 \cdot 4 & 7 \cdot -8 \end{array}\right]$$ $$ = \left[\begin{array}{ccc}9 & 4 & -8 \\ -18 & -8 & 16 \\ 63 & 28 & -56 \end{array}\right]$$ As we can clearly see from the example, product matrix AB and product matrix BA are different matrices. This shows that matrix multiplication is not commutative, which means we have to be careful about the order when multiplying two matrices together.
Example #3: Find AB. $$A = \left[\begin{array}{ccc}1 & 2 & 4 \\ 2 & 6 & 5\end{array}\right]$$ $$B = \left[\begin{array}{cc}1 & 0 \\ -1 & -2 \\6 & 3\end{array}\right]$$ Since A is a 2 × 3 matrix and B is a 3 × 2 matrix, we can perform the multiplication. The number of columns in matrix A is 3, and the number of rows in matrix B is also 3. Our product will be a 2 × 2 matrix. This comes from the number of rows from matrix A, which is 2, and the number of columns from matrix B, which is also 2. $$AB = \left[\begin{array}{ccc}1 & 2 & 4 \\ 2 & 6 & 5\end{array}\right] \left[\begin{array}{cc}1 & 0 \\ -1 & -2 \\6 & 3\end{array}\right] = \left[\begin{array}{cc}\_ & \_ \\ \_ & \_ \end{array}\right]$$ To find the product, think about each element in the product matrix AB. For the position of (row 1, col 1), we use the first row of matrix A and the first column of matrix B. Then for the position of (row 1, col 2), we will use the first row of matrix A and the second column of matrix B. We will continue with this pattern to fill in all elements of the product matrix AB. $$AB = \left[\begin{array}{ccc}1 & 2 & 4 \\ 2 & 6 & 5\end{array}\right] \left[\begin{array}{cc}1 & 0 \\ -1 & -2 \\6 & 3\end{array}\right]$$ $$= \left[\begin{array}{cc}1 \cdot 1 + 2 \cdot -1 + 4 \cdot 6 & 1 \cdot 0 + 2 \cdot -2 + 4 \cdot 3 \\ 2\cdot 1 + 6 \cdot -1 + 5 \cdot 6 & 2 \cdot 0 + 6 \cdot -2 + 5 \cdot 3 \end{array}\right]$$ $$= \left[\begin{array}{cc}1 -2 + 24 & 0 -4 + 12 \\ 2 -6 + 30 & 0 -12 + 15 \end{array}\right]$$ $$= \left[\begin{array}{cc}23 & 8 \\ 26 & 3 \end{array}\right]$$ As we previously discussed in our lesson on the introduction to matrices, we may have variables involved with the elements of a matrix. These will be lowercase letters such as x, y, and z. The uppercase letters are normally reserved for matrix names. Let's look at an example.
Example #4: Find AB. $$A = \left[\begin{array}{cc}x & -xy\\ -6xy & 3x \\ -5 & 5x\end{array}\right]$$ $$B = \left[\begin{array}{cc}2xy & 5x\\ -1 & 0\end{array}\right]$$ Since A is a 3 × 2 matrix and B is a 2 × 2 matrix, we can perform the multiplication. The number of columns in matrix A is 2, and the number of rows in matrix B is also 2. Our product will be a 3 × 2 matrix. This comes from the number of rows from matrix A, which is 3, and the number of columns from matrix B, which is 2. $$AB = \left[\begin{array}{cc}x & -xy\\ -6xy & 3x \\ -5 & 5x\end{array}\right] \left[\begin{array}{cc}2xy & 5x\\ -1 & 0\end{array}\right] = \left[\begin{array}{cc}\_ & \_\\ \_ & \_ \\ \_ & \_\end{array}\right]$$ To find the product, think about each element in the product matrix AB. For the position of (row 1, col 1), we use the first row of matrix A and the first column of matrix B. Then for the position of (row 1, col 2), we will use the first row of matrix A and the second column of matrix B. We will continue with this pattern to fill in all elements of the product matrix AB. $$AB = \left[\begin{array}{cc}x & -xy\\ -6xy & 3x \\ -5 & 5x\end{array}\right] \left[\begin{array}{cc}2xy & 5x\\ -1 & 0\end{array}\right]$$ $$= \left[\begin{array}{cc}x \cdot 2xy + -xy \cdot -1 & x \cdot 5x + -xy \cdot 0\\ -6xy \cdot 2xy + 3x \cdot -1 & -6xy \cdot 5x + 3x \cdot 0\\ -5 \cdot 2xy + 5x \cdot -1 & -5 \cdot 5x + 5x \cdot 0\end{array}\right]$$ $$= \left[\begin{array}{cc}2x^2y + xy & 5x^2 \\ -12x^2y^2 - 3x & -30x^2y \\ -10xy - 5x & -25x \end{array}\right]$$
Multiplying More Than Two Matrices
In some cases, we may be asked to find the product of more than two matrices. Remember that matrix multiplication is not commutative but is associative. The order in which the matrices appear in the multiplication problem does matter. We saw in an earlier example that in general AB ≠ BA. The same would be true with more than two matrices involved. Something like ABC would generally not be the same if we had a different order such as BAC or CBA. Since matrix multiplication is associative, we can change the grouping of our matrices when we multiply. We just have to preserve the order in which the matrices appear in the problem.(AB)C » product matrix AB is found first, then multiplied by matrix C. Product matrix AB must stay on the left for the final operation.
A(BC) » product matrix BC is found first, then multiplied by matrix A. Matrix A must stay on the left for the final operation.
To see this in action, let's look at an example.
Example #5: Find ABC. $$A = \left[\begin{array}{ccc}5 & 3 & 0\end{array}\right]$$ $$B = \left[\begin{array}{cc}1 & 2 \\ -2 & -6 \\3 & 6\end{array}\right]$$ $$C = \left[\begin{array}{ccc}-2 & -4 \\4 & -2\end{array}\right]$$ We will find our product matrix ABC in two different ways to show the associative property of matrix multiplication. First, let's group our multiplication with the first two in parentheses.
(AB)C » This tells us to find the product matrix AB first and then multiply by matrix C last to obtain the product matrix ABC. $$AB = \left[\begin{array}{ccc}5 & 3 & 0\end{array}\right] \left[\begin{array}{cc}1 & 2 \\ -2 & -6 \\3 & 6\end{array}\right] = \left[\begin{array}{cc}\_ & \_\end{array}\right]$$ The product matrix AB will be a 1 × 2 matrix since matrix A is a 1 × 3 and matrix B is a 3 × 2. $$AB = \left[\begin{array}{ccc}5 & 3 & 0\end{array}\right] \left[\begin{array}{cc}1 & 2 \\ -2 & -6 \\3 & 6\end{array}\right]$$ $$= \left[\begin{array}{cc}5 \cdot 1 + 3 \cdot -2 + 0 \cdot 3 & 5 \cdot 2 + 3 \cdot -6 + 0 \cdot 6\end{array}\right]$$ $$= \left[\begin{array}{cc}5 - 6 + 0 & 10 - 18 + 0\end{array}\right]$$ $$= \left[\begin{array}{cc}-1 & -8\end{array}\right]$$ Now, let's find the product matrix ABC, which is the product matrix AB multiplied by matrix C. $$ABC = \left[\begin{array}{cc}-1 & -8\end{array}\right] \left[\begin{array}{ccc}-2 & -4 \\4 & -2\end{array}\right] = \left[\begin{array}{cc}\_ & \_\end{array}\right]$$ The product matrix ABC will be a 1 × 2 matrix since the product matrix AB is a 1 × 2 and matrix C is a 2 × 2. $$ABC = \left[\begin{array}{cc}-1 & -8\end{array}\right] \left[\begin{array}{ccc}-2 & -4 \\4 & -2\end{array}\right]$$ $$= \left[\begin{array}{cc} -1 \cdot -2 + -8 \cdot 4 & -1 \cdot -4 + -8 \cdot -2\end{array}\right]$$ $$= \left[\begin{array}{cc} 2 - 32 & 4 + 16\end{array}\right]$$ $$= \left[\begin{array}{cc} -30 & 20\end{array}\right]$$ Now, let's redo the problem but use a different grouping.
A(BC) » This tells us to find the product matrix BC first and then multiply matrix A by the product matrix BC last to obtain the product matrix ABC. $$BC = \left[\begin{array}{cc}1 & 2 \\ -2 & -6 \\3 & 6\end{array}\right] \left[\begin{array}{ccc}-2 & -4 \\4 & -2\end{array}\right] = \left[\begin{array}{cc}\_ & \_ \\ \_ & \_ \\\_ & \_\end{array}\right]$$ The product matrix BC will be a 3 × 2 matrix since matrix B is a 3 × 2 and matrix C is a 2 × 2. $$BC = \left[\begin{array}{cc}1 & 2 \\ -2 & -6 \\3 & 6\end{array}\right] \left[\begin{array}{ccc}-2 & -4 \\4 & -2\end{array}\right]$$ $$= \left[\begin{array}{cc}1 \cdot -2 + 2 \cdot 4 & 1 \cdot -4 + 2 \cdot -2\\ -2 \cdot -2 + -6 \cdot 4 & -2 \cdot -4 + -6 \cdot -2 \\ 3 \cdot -2 + 6 \cdot 4 & 3 \cdot -4 + 6 \cdot -2\end{array}\right]$$ $$= \left[\begin{array}{cc}-2 + 8 & -4 - 4\\ 4 - 24 & 8 + 12 \\ -6 + 24 & -12 - 12\end{array}\right]$$ $$= \left[\begin{array}{cc}6 & -8\\ -20 & 20 \\ 18 & -24\end{array}\right]$$ Now, let's find the product matrix ABC, which is matrix A multiplied by the product matrix BC. $$ABC = \left[\begin{array}{ccc}5 & 3 & 0\end{array}\right] \left[\begin{array}{cc}6 & -8\\ -20 & 20 \\ 18 & -24\end{array}\right] = \left[\begin{array}{cc}\_ & \_ \end{array}\right]$$ The product matrix ABC will be a 1 × 2 matrix since matrix A is a 1 × 3 and product matrix BC is a 3 × 2. $$ABC = \left[\begin{array}{ccc}5 & 3 & 0\end{array}\right] \left[\begin{array}{cc}6 & -8\\ -20 & 20 \\ 18 & -24\end{array}\right]$$ $$ = \left[\begin{array}{cc}5 \cdot 6 + 3 \cdot -20 + 0 \cdot 18 & 5 \cdot -8 + 3 \cdot 20 + 0 \cdot -24 \end{array}\right]$$ $$ = \left[\begin{array}{cc}30 - 60 + 0 & -40 + 60 + 0 \end{array}\right]$$ $$ = \left[\begin{array}{cc}-30 & 20 \end{array}\right]$$ Notice that we found the same product matrix ABC from (AB)C and A(BC), which shows a clear example of the associative property of matrix multiplication. Note: Be very careful when using this property as we know that matrix multiplication is not commutative. The associative property of matrix multiplication only allows us to change the grouping but not the order. In our second example, notice how we kept A on the left.
Skills Check:
Example #1
Find AB. $$A=\left[ \begin{array}{cc}-4&6\\ -4&-3\end{array}\right] $$ $$B=\left[ \begin{array}{cc}5&1\\ -3&2\end{array}\right] $$
Please choose the best answer.
Example #2
Find AB. $$A=\left[ \begin{array}{ccc}2&-2 & 0\\ -2&-5 & 4\end{array}\right] $$ $$B=\left[ \begin{array}{cc}-3&-6\\ 1&-2 \\-5 & -2\end{array}\right] $$
Please choose the best answer.
Example #3
Find ABC. $$A = \left[ \begin{array}{cc}5 & 5\\ -3 & -1 \\-4 & -2\end{array}\right]$$ $$B = \left[ \begin{array}{cc}3 & 5\\ -2 & -5\end{array}\right]$$ $$C = \left[ \begin{array}{cc}-1 & 0\\ 6 & 6\end{array}\right]$$
Please choose the best answer.
Congrats, Your Score is 100%
Better Luck Next Time, Your Score is %
Try again?
Ready for more?
Watch the Step by Step Video Lesson Take the Practice Test