4.3: Matrix Multiplication
Compatible Matrices
We are going to multiply together two matrices, one of size \(m\times n\) , and one of size \(n\times p\) . The multiplication will be possible, and the product exists because the sizes make them compatible with each other.
Notice the number of columns of the leftmost matrix is equal to the number of rows of the rightmost matrix.
For the product, \(A \cdot B\), of two matrices to exist it must be that (the number of columns of matrix \(A\) ) = (the number of rows of matrix \(B\)) Matrices for which this is true are said to be compatible with each other.
Matrices as Collections of Row and Column Matrices
It is productive to think of a matrix as a collection of individual row matrices and column matrices.For example, we can think of the matrix \(A=\left[ \begin{array}{cc} 3 & 1 \\ --4 & 2 \\ 0 & 5 \end{array} \right]\) as being composed of
- the three row matrices, \(\left[ \begin{array}{cc} 3 & 1 \end{array} \right],\ \ \left[ \begin{array}{cc} --4 & 2 \end{array} \right],\) and \(\left[ \begin{array}{cc} 0 & 5 \end{array} \right],\ \) and
- the two column matrices \(\left[ \begin{array}{c} 3 \\ --4 \\ 0 \end{array} \right]\) and \(\left[ \begin{array}{c} 1 \\ 2 \\ 5 \end{array} \right]\) .
(If you need a review of row and column matrices, see Section 4.2)
Multiplication of Two Matrices
To multiply two compatible matrices \(A\) and \(B\) together, multiply every row matrix of \(A\) through every column matrix of \(B\).
Suppose the size of matrix \(A\) is \(3\times 4\) and the size of matrix \(B\) is \(4\times 5\) . The matrices are compatible with each other and the size of the product is \(3\times 5\)
Some of the entries of the product \(A\bullet B\) are
\(a_{11}\) : The entry in row 1, column 1, is the result of multiplying the
1st row of matrix \(A\) through the 1st column of matrix \(B\) .
\(a_{12}\) : The entry in row 1, column 2, is the result of multiplying the
1st row of matrix \(A\) through the 2nd column of matrix \(B\) .
\(a_{24}\) : The entry in row 2, column 4, is the result of multiplying the
2nd row of matrix \(A\) through the 4th column of matrix \(B\) .
\(a_{35}\) : The entry in row 3, column \(5\) , is the result of multiplying the
3rd row of matrix \(A\) through the 5th column of matrix \(B\) .
\(a_{33}\) : The entry in row 3, column 3, is the result of multiplying the
3rd row of matrix \(A\) through the 3rd column of matrix \(B\) .
Do you see the general rule for producing any particular entry?
To get the entry in row \(i\) and column \(\ j\) , \(a_{ij},\ \) multiply
the \(ith\) row of matrix \(A\) through the \(jth\) column of matrix \(B.\)
Compute the product of the matrices \(A=\left[ \begin{array}{cc} 3 & 1 \\ --4 & 2 \\ 0 & 5 \end{array} \right]\) and \(B=\left[ \begin{array}{cc} 3 & 2 \\ 4 & 1 \end{array} \right]\) .
First note that the two matrices are compatible
Solution
\[A \cdot B=\left[\begin{array}{cc}
3 & 1 \\
-4 & 2 \\
0 & 5
\end{array}\right] \cdot\left[\begin{array}{ll}
3 & 2 \\
4 & 1
\end{array}\right] \nonumber \]
The product is the \(3\times 2\) matrix of the form \(\left[ \begin{array}{cc} a_{11} & a_{12} \\ a_{21} & a_{22} \\ a_{31} & a_{32} \end{array} \right]\)
Since we are multiplying 3 rows through 2 columns, there will be 6 entries. The six entries of \(A\bullet B\) are
\(a_{11}=\ \) the 1st row of \(A\) times the 1st column of \(B\)
\[=\left[\begin{array}{ll}
3 & 1
\end{array}\right] \cdot\left[\begin{array}{l}
3 \\
4
\end{array}\right]=[3 \cdot 3+1 \cdot 4]=[13] \nonumber \]
\(a_{12}=\ \) the 1st row of \(A\) times the 2nd column of \(B\)
\[=\left[\begin{array}{ll}
3 & 1
\end{array}\right] \cdot\left[\begin{array}{l}
2 \\
1
\end{array}\right]=[3 \cdot 2+1 \cdot 1]=[7] \nonumber \]
\(a_{21}=\ \) the 2nd row of \(A\) times the 1st column of \(B\)
\[=\left[\begin{array}{ll}
-4 & 2
\end{array}\right] \cdot\left[\begin{array}{l}
3 \\
4
\end{array}\right]=[-4 \cdot 3+2 \cdot 4]=[-4] \nonumber \]
\(a_{22}=\ \) the 2nd row of \(A\) times the 2nd column of \(B\)
\[=\left[\begin{array}{ll}
-4 & 2
\end{array}\right] \cdot\left[\begin{array}{l}
2 \\
1
\end{array}\right]=[-4 \cdot 2+2 \cdot 1]=[-6] \nonumber \]
\(a_{31}=\ \) the 3rd row of \(A\) times the 1st column of \(B\)
\[=\left[\begin{array}{ll}
0 & 5
\end{array}\right] \cdot\left[\begin{array}{l}
3 \\
4
\end{array}\right]=[0 \cdot 3+5 \cdot 4]=[20] \nonumber \]
\(a_{32}=\) the 3rd row of \(A\) times the 2nd column of \(B\)
\[=\left[\begin{array}{ll}
0 & 5
\end{array}\right] \cdot\left[\begin{array}{l}
2 \\
1
\end{array}\right]=[0 \cdot 2+5 \cdot 1]=[5] \nonumber \]
So, \(A \cdot B=\left[\begin{array}{cc}
13 & 7 \\
-4 & -6 \\
20 & 5
\end{array}\right]\)
Your Turn : Show that the product of the matrices \(A\mathrm{=}\left[ \begin{array}{cc} \mathrm{2} & \mathrm{3} \\ \mathrm{4} & \mathrm{1} \end{array} \right]\) and \(B\mathrm{=}\left[ \begin{array}{ccc} \mathrm{2} & \mathrm{3} & 0 \\ \mathrm{1} & \mathrm{2} & \mathrm{4} \end{array} \right]\) is \(\left[ \begin{array}{ccc} \mathrm{7} & \mathrm{12} & \mathrm{12} \\ \mathrm{9} & \mathrm{14} & \mathrm{4} \end{array} \right]\) .
Using Technology
You can see that multiplying matrices together involves a lot of arithmetic and can be cumbersome. We can use technology to help us through the process.
Go to www.wolframalpha.com.
To find the product of the two matrices of above Your Turn Example, enter [[2,3], [4,1]] * [[2,3,0], [1,2,4]] in the entry field. WolframAlpha sees a matrix as a collection of row matrices.
Both entries and rows are separated by commas and WA does not see spaces.
Wolframalpha tells you what it thinks you entered, then tells you its answer \(\left[ \begin{array}{ccc} 7 & 12 & 12 \\ 9 & 14 & 4 \end{array} \right]\) .
Try these
\[A=\left[\begin{array}{cc}
1 & 2 \\
-1 & 3 \\
0 & 4
\end{array}\right] \quad B=\left[\begin{array}{cc}
3 & 2 \\
1 & 0 \\
-1 & -2
\end{array}\right] \quad C=\left[\begin{array}{lll}
2 & 1 & 3 \\
4 & 2 & 1
\end{array}\right] \quad D=\left[\begin{array}{cc}
-2 & 6 \\
4 & 1
\end{array}\right] \quad E=\left[\begin{array}{l}
5 \\
2
\end{array}\right] \quad F=\left[\begin{array}{l}
2 \\
1 \\
5
\end{array}\right] \nonumber \]
\(A \cdot C\)
- Answer
-
\(\left[ \begin{array}{ccc} 10 & 5 & 5 \\ 10 & 5 & 0 \\ 16 & 8 & 4 \end{array} \right]\)
\(C \cdot A\)
- Answer
-
\(\left[ \begin{array}{cc} 1 & 19 \\ 2 & 18 \end{array} \right]\)
Compare your answers to question 1 and 2. If you got them right, would you say that matrix multiplication is or is not commutative?
- Answer
-
Is not commutative
\(D \cdot C\)
- Answer
-
\(\left[ \begin{array}{ccc} 20 & 10 & 0 \\ 12 & 6 & 13 \end{array} \right]\)
\(C \cdot F\)
- Answer
-
\(\left[ \begin{array}{c} 20 \\ 15 \end{array} \right]\)
\(A \cdot E\)
- Answer
-
\(\left[ \begin{array}{c} 9 \\ 1 \\ 8 \end{array} \right]\)
\(D^2\)
- Answer
-
\(\left[ \begin{array}{cc} 28 & -6 \\ -4 & 25 \end{array} \right]\)
\(D \cdot\left[\begin{array}{ll}
1 & 0 \\
0 & 1
\end{array}\right]\)
- Answer
-
\(D\)
\(B \cdot D\)
- Answer
-
\(\left[ \begin{array}{cc} 2 & 20 \\ -2 & 6 \\ -6 & -8 \end{array} \right]\)
\(B \cdot D \cdot C\)
- Answer
-
\(\left[ \begin{array}{ccc} 84 & 42 & 26 \\ 20 & 10 & 0 \\ -44 & -22 & -26 \end{array} \right]\)
\(D \cdot B\)
- Answer
-
Not defined