Introduction to matrices
Matrix multiplication requires you to be able to identify the shape or order of a matrix. Use this resource to review this concept.
A strong understanding of how to multiply matrices is critical in many fields, like computer science, robotics, statistics and economics. Just as there are rules for adding and subtracting matrices, we can multiply matrices with each other when certain requirements are met. Use this resource to learn how to multiply matrices.
Before you begin, make sure you understand the basics of matrices, including how to identify the shape or order of a matrix.
Two matrices can be multiplied if the number of columns of the first matrix is the same as the number of rows of the second matrix.
Matrix multiplication results in a new matrix with the number of rows from the first matrix and the number of columns from the second matrix. This operation is only defined if the number of columns in the first matrix equals the number of rows in the second matrix.
For instance, if matrix \(A\) is \(m\times p\) and matrix \(B\) is \(q\times n\), then \(A\times B=AB\) is possible if \(p=q\). If \(p\neq q\), the product is undefined or does not exist. For example, a \(2\times3\) matrix can't be multiplied by a \(1\times4\) matrix, but can be multiplied by a \(3\times2\) matrix to produce a \(2\times2\) matrix.
The process of multiply matrices is a bit confusing. We can summarise it using the figure, but let's look at some examples.
Consider matrices \(A\) and \(B\).
\[A = \left[ \begin{array}{ccc} 2 & 4 & 5\\
7 & 8 & 9 \
\end{array} \right]\quad
B = \left[ \begin{array}{cc} 1 & 6\\
3 & 1\\
4 & 2
\end{array} \right] \] Find the product \(AB\), if it exists.
First, identify the orders of the matrices to determine whether multiplication is possible. \(A\) is a \(2\times3\) matrix and \(B\) is a \(3\times2\) matrix. Matrix multiplication is possible since \(A\) has \(3\) columns and \(B\) has \(3\) rows. The result will be a matrix with the same number of rows as \(A\) and columns as \(B\), so \(2\times2\).
We'll work through the multiplication one element at a time. First, we find the first element in row \(1\) of the final matrix \(AB\). To do this, we multiply each element in row \(1\) of \(A\) by the corresponding element in column \(1\) of \(B\), then add them altogether.
\[\begin{align*} AB & = \left[ \begin{array}{ccc} 2 & 4 & 5\\
7 & 8 & 9
\end{array} \right]
\left[ \begin{array}{cc} 1 & 6\\
3 & 1\\
4 & 2
\end{array} \right]\\
& = \left[ \begin{array}{cc} (2\times1)+(4\times3)+(5\times4) & \textrm{element 2 of row 1}\\
\textrm{element 1 of row 2} & \textrm{element 2 of row 2}
\end{array} \right]\\
& = \left[ \begin{array}{cc} 2+12+20 & \textrm{element 2 of row 1}\\
\textrm{element 1 of row 2} & \textrm{element 2 of row 2}
\end{array} \right]\\
& = \left[ \begin{array}{cc} 34 & \textrm{element 2 of row 1}\\
\textrm{element 1 of row 2} & \textrm{element 2 of row 2}
\end{array} \right]
\end{align*}\]
To find the second element in row \(1\) of matrix \(AB\), we multiply each element in row \(1\) of \(A\) by the corresponding element in column \(2\) of \(B\), then add them altogether.
\[\begin{align*} AB & = \left[ \begin{array}{ccc} 2 & 4 & 5\\
7 & 8 & 9
\end{array} \right]
\left[ \begin{array}{cc} 1 & 6\\
3 & 1\\
4 & 2
\end{array} \right]\\
& = \left[ \begin{array}{cc} 34 & (2\times6)+(4\times1)+(5\times2)\\
\textrm{element 1 of row 2} & \textrm{element 2 of row 2}
\end{array} \right]\\
& = \left[ \begin{array}{cc} 34 & 12+4+10\\
\textrm{element 1 of row 2} & \textrm{element 2 of row 2}
\end{array} \right]\\
& = \left[ \begin{array}{cc} 34 & 26\\
\textrm{element 1 of row 2} & \textrm{element 2 of row 2}
\end{array} \right]
\end{align*}\]
To find the first element in row \(2\), we multiply each element in row \(2\) of \(A\) by the corresponding element in column \(1\) of \(B\), then add them together.
\[\begin{align*} AB & = \left[ \begin{array}{ccc} 2 & 4 & 5\\
7 & 8 & 9
\end{array} \right]
\left[ \begin{array}{cc} 1 & 6\\
3 & 1\\
4 & 2
\end{array}\right]\\
& = \left[ \begin{array}{cc} 34 & 26\\
(7\times1)+(8\times3)+(9\times4) & \textrm{element 2 of row 2}
\end{array} \right]\\
& = \left[ \begin{array}{cc} 34 & 26\\
7+24+36 & \textrm{element 2 of row 2}
\end{array} \right]\\
& = \left[ \begin{array}{cc} 34 & 26\\
67 & \textrm{element 2 of row 2}
\end{array} \right]
\end{align*}\]
Finally, to find the second element in row \(2\), we multiply each element in row \(2\) of \(A\) by the corresponding element in column \(2\) of \(B\), then add them together.
\[\begin{align*} AB & = \left[ \begin{array}{ccc} 2 & 4 & 5\\
7 & 8 & 9
\end{array} \right]
\left[ \begin{array}{cc} 1 & 6\\
3 & 1\\
4 & 2
\end{array}\right]\\
& = \left[ \begin{array}{cc} 34 & 26\\
67 & (7\times6)+(8\times1)+(9\times2)
\end{array} \right]\\
& = \left[ \begin{array}{cc} 34 & 26\\
7+24+36 & 42+8+18
\end{array} \right]\\
& = \left[ \begin{array}{cc} 34 & 26\\
67 & 68
\end{array} \right]
\end{align*}\]
\(A\) is \(2\times2\) and \(B\) is \(2\times3\), so \(AB\) will be a \(2\times3\) matrix.
\(BA\) cannot be defined since the number of columns in \(B\) is \(3\) and the number of rows in \(A\) is \(2\). They are unequal, so \(BA\) does not exist.
\(A\) is a square matrix. Since it has the same number of columns and rows, we can complete the matrix multiplication, i.e. \(AA\) exists or is defined.
\[\begin{align*} AA & = \left[ \begin{array}{cc} 2 & 1\\
3 & 0
\end{array} \right]
\left[ \begin{array}{cc} 2 & 1\\
3 & 0
\end{array} \right]\\
& = \left[ \begin{array}{cc} (2\times2)+(1\times3) & (2\times1)+(1\times0)\\
(3\times2)+(0\times3) & (3\times1)+(0\times0)
\end{array} \right]\\
& = \left[ \begin{array}{cc} 7 & 2\\
6 & 3
\end{array} \right]
\end{align*}\]
\(B\) is not a square matrix. Its number of columns and rows is unequal, so \(BB\) is undefined. It does not exist.
Since the number of columns and rows is the same for matrices \(A\) and \(B\), both \(AB\) and \(BA\) exist. The products of both will be \(2\times2\) matrices.
\[\begin{align*} AB & = \left[ \begin{array}{cc} 2 & -1\\
1 & 3
\end{array} \right]
\left[ \begin{array}{cc} 1 & 0\\
2 & -1
\end{array} \right]\\
& = \left[ \begin{array}{cc} (2\times1)+(\left(-1\right)\times2) & (2\times0)+(\left(-1\right)\times\left(-1\right))\\
(1\times1)+(3\times2) & (1\times0)+(3\times\left(-1\right))
\end{array} \right]\\
& = \left[ \begin{array}{cc} 0 & 1\\
7 & -3
\end{array} \right]
\end{align*}\] \[\begin{align*} BA & = \left[ \begin{array}{cc} 1 & 0\\
2 & -1
\end{array} \right]
\left[ \begin{array}{cc} 2 & -1\\
1 & 3
\end{array} \right]\\
& = \left[ \begin{array}{cc} (1\times2)+(0\times1) & (1\times\left(-1\right))+(0\times3)\\
(2\times2)+(\left(-1\right)\times1) & (2\times\left(-1\right))+(\left(-1\right)\times3) \end{array}\right]\\
& = \left[ \begin{array}{cc} 2 & -1\\
3 & -5
\end{array} \right]
\end{align*}\]
From this example, we can see that, in most cases, \(AB\neq BA\). We say that matrix multiplication is not commutative and the order of multiplication matters. There is an exception to this: when multiplying by a unit matrix.
Remember that a square matrix with \(1\)'s along its leading diagonal and zeros elsewhere is called a unit or identity matrix. The order of the unit matrix is sometimes noted with a subscript. For example:
\[\begin{align*} I_{1} & = \left[1\right]\quad
I_{2} = \left[ \begin{array}{cc} 1 & 0\\
0 & 1
\end{array} \right]\quad
I_{3} = \left[ \begin{array}{ccc} 1 & 0 & 0\\
0 & 1 & 0\\
0 & 0 & 1
\end{array} \right]\\
I_{4} & = \left[ \begin{array}{cccc} 1 & 0 & 0 & 0\\
0 & 1 & 0 & 0\\
0 & 0 & 1 & 0\\
0 & 0 & 0 & 1
\end{array} \right]\quad
I_{n} = \left[ \begin{array}{ccccc} 1 & 0 & 0 & \cdots & 0\\
0 & 1 & 0 & \cdots & 0\\
0 & 0 & 1 & \cdots & 0\\
\vdots & \vdots & \vdots & \ddots & \vdots\\
0 & 0 & 0 & \cdots & 1
\end{array} \right]
\end{align*}\]
The unit matrix acts like the number \(1\) in the real number system. When you multiply by the unit matrix, the original matrix remains unchanged.
When you multiply a square matrix \(n\times n\) by a unit matrix \(I_{n}\), the order of multiplication does not matter. That is:
\[AI_{n}=I_{n}A\]
Consider matrix \(A\).
\[A = \left[ \begin{array}{cc} 1 & 2\\
3 & 4
\end{array} \right]\] Show that \(AI\) is the same as \(IA\).
Since \(A\) has two columns, we need the unit matrix to have two rows and two columns. Therefore, \(I=\left[\begin{array}{cc} 1 & 0\\ 0 & 1 \end{array}\right]\).
\[\begin{align*} AI & = \left[ \begin{array}{cc} 1 & 2\\
3 & 4
\end{array} \right]
\left[ \begin{array}{cc} 1 & 0\\
0 & 1
\end{array} \right]\\
& = \left[ \begin{array}{cc} (1\times1)+(2\times0) & (1\times0)+(2\times1)\\
(3\times1)+(3\times0) & (3\times0)+(4\times1)
\end{array} \right]\\
& = \left[ \begin{array}{cc} 1 & 2\\
3 & 4
\end{array} \right]\\
& = A \end{align*}\] \[ \begin{align*} IA & = \left[ \begin{array}{cc} 1 & 0\\
0 & 1
\end{array} \right]
\left[ \begin{array}{cc} 1 & 2\\
3 & 4
\end{array} \right]\\
& = \left[ \begin{array}{cc} (1\times1)+(0\times3) & (1\times2)+(0\times4)\\
(0\times1)+(1\times3) & (0\times2)+(1\times4)
\end{array} \right]\\
& =\left[ \begin{array}{cc} 1 & 2\\
3 & 4
\end{array} \right]\\
& = A
\end{align*}\] So, \(AI=IA=A\).
Images on this page by RMIT, licensed under CC BY-NC 4.0