Skip to main content

Section 17.2 Matrix Multiplication

Definition 17.2.1.

Let \(A=\left(a_{ij}\right)_{m \times n}\) and \(B = \left(b_{ij}\right)_{n \times p}\text{.}\) Then matrix multiplication is defined by
\begin{equation*} AB = \left(\sum_{k=1}^n a_{ik}b_{kj}\right)_{m \times p}. \end{equation*}

If we call \(C=AB\) then from this definition it can be seen:

  1. For the matrix multiplication \(AB\) to be defined the number of columns in \(A\) has to be equal to the number of rows in \(B\text{.}\) The resulting matrix, \(C\text{,}\) has the same number of rows as \(A\) and the same number of columns as \(B\text{.}\)

  2. Entry \(c_{ij}\) in \(C\) is found by taking the scalar (or dot) product of the \(i^{\mbox{th}}\) row vector from \(A\) with (the transpose of) the \(j^{\mbox{th}}\) column vector from \(B\text{,}\) i.e.

    \begin{align*} c_{ij} \amp = (a_{i1},a_{i2}, \ldots, a_{in})\cdot (b_{1j},b_{2j}, \ldots, b_{nj}) \\ \amp = a_{i1}b_{1j} + a_{i2}b_{2j} + \cdots + a_{in}b_{nj}. \end{align*}

Let

\begin{equation*} A=\begin{pmatrix} 0 \amp 1 \\ -1 \amp 3 \\ 2 \amp 5 \end{pmatrix} \quad \mbox{and} \quad B=\begin{pmatrix} -2 \amp 1/2 \\ -3 \amp 4 \end{pmatrix}. \end{equation*}
  1. Calculate \(AB\text{.}\)

  2. Calculate \(BA\text{.}\)

Answer.
  1. \(\displaystyle AB=\begin{pmatrix} -3 \amp 4 \\ -7 \amp 23/2 \\ -19 \amp 21 \end{pmatrix}\)

  2. \(BA\) is not defined.

Solution.
  1. Since \(A\) is a \(3 \times 2\) matrix and \(B\) is \(2\times 2\) then \(AB\) is defined since \(A\) has \(2\) columns and \(B\) has \(2\) rows. The resultant matrix will be a \(3 \times 2\) matrix since \(A\) has \(3\) rows and \(B\) has \(2\) columns. Thus \(AB\) will be of the form

    \begin{equation*} AB = \begin{pmatrix}c_{11} \amp c_{12}\\ c_{21} \amp c_{22}\\ c_{31} \amp c_{32}\end{pmatrix}. \end{equation*}

    Now

    \begin{align*} c_{11} \amp = (0,1)\cdot (-2,-3) = 0 -3 = -3 \\ c_{12} \amp = (0,1)\cdot (1/2,4) = 0 + 4 = 4 \\ c_{21} \amp = (-1,3)\cdot (-2,-3) = 2 - 9 = -7 \\ c_{22} \amp = (-1,3)\cdot (1/2,4) = -1/2 +12 = 23/2 \\ c_{31} \amp = (2,5)\cdot (-2,-3) = -4 -15 = -19 \\ c_{32} \amp = (2,5)\cdot (1/2,4) = 1 + 20 = 21 \end{align*}

    and so

    \begin{equation*} AB=\begin{pmatrix} -3 \amp 4 \\ -7 \amp 23/2 \\ -19 \amp 21 \end{pmatrix}. \end{equation*}
  2. \(BA\) is not defined because the number of columns in \(B\) (i.e. 2) is not equal to the number of rows in \(A\) (i.e. 3).

Notice that this example shows that matrix multiplication is not commutative, i.e. in general

\begin{equation*} AB \neq BA. \end{equation*}

Let

\begin{equation*} A=\begin{pmatrix} 3\amp 2 \amp 1 \amp 6 \\ 2 \amp 1 \amp 3 \amp -1\end{pmatrix}, \quad B=\begin{pmatrix} 1 \amp 0 \\ -1 \amp 2 \\ 3 \amp 1 \\ 4 \amp 5 \end{pmatrix}, \quad C =\begin{pmatrix}-2 \amp 1 \amp 0 \\ 4 \amp -1 \amp 3\end{pmatrix}. \end{equation*}
  1. Calculate \(A(BC)\text{.}\)

  2. Calculate \((AB)C\text{.}\)

Answer.

\(A(BC) = \begin{pmatrix}84 \amp -7 \amp 105 \\ -12 \amp 6 \amp 0\end{pmatrix} = (AB)C\)

Solution.
  1. \(BC = \begin{pmatrix} 1 \amp 0 \\ -1 \amp 2 \\ 3 \amp 1 \\ 4 \amp 5 \end{pmatrix}\begin{pmatrix}-2 \amp 1 \amp 0 \\ 4 \amp -1 \amp 3\end{pmatrix} = \begin{pmatrix} -2 \amp 1 \amp 0\\ 10 \amp -3 \amp 6 \\ -2 \amp 2 \amp 3 \\ 12 \amp -1 \amp 15\end{pmatrix}\)

    \begin{equation*} A(BC) = \begin{pmatrix} 3\amp 2 \amp 1 \amp 6 \\ 2 \amp 1 \amp 3 \amp -1\end{pmatrix}\begin{pmatrix} -2 \amp 1 \amp 0\\ 10 \amp -3 \amp 6 \\ -2 \amp 2 \amp 3 \\ 12 \amp -1 \amp 15\end{pmatrix} = \begin{pmatrix} 84 \amp -7 \amp 105 \\ -12 \amp 6 \amp 0\end{pmatrix}. \end{equation*}
  2. \(AB = \begin{pmatrix} 3\amp 2 \amp 1 \amp 6 \\ 2 \amp 1 \amp 3 \amp -1\end{pmatrix} \begin{pmatrix} 1 \amp 0 \\ -1 \amp 2 \\ 3 \amp 1 \\ 4 \amp 5 \end{pmatrix} = \begin{pmatrix} 28 \amp 35 \\ 6 \amp 0\end{pmatrix}\)

    \begin{equation*} (AB)C = \begin{pmatrix} 28 \amp 35 \\ 6 \amp 0\end{pmatrix} \begin{pmatrix}-2 \amp 1 \amp 0 \\ 4 \amp -1 \amp 3\end{pmatrix} = \begin{pmatrix}84 \amp -7 \amp 105 \\ -12 \amp 6 \amp 0\end{pmatrix}. \end{equation*}

Notice that this example is an illustration that matrix multiplication is associative, i.e. in general

\begin{equation*} A(BC) = (AB)C\text{.} \end{equation*}

From the definition of matrix multiplication the following properties can be shown to hold.

For later reference, some properties of the transpose of a matrix with respect to the various matrix operations that we have been discussing are listed below.

Confirm that \((AB)^T = B^T A^T\) holds for the matrices

\begin{equation*} A = \begin{pmatrix}0 \amp 1\\ -1 \amp 3 \\ 2 \amp 5\end{pmatrix} \quad \mbox{and} \quad B = \begin{pmatrix}-2 \amp 1/2 \\ -3 \amp 4 \end{pmatrix}. \end{equation*}
Solution.

Firstly

\begin{align*} (AB)^T \amp = \left( \begin{pmatrix}0 \amp 1\\ -1 \amp 3 \\ 2 \amp 5\end{pmatrix} \begin{pmatrix}-2 \amp 1/2 \\ -3 \amp 4 \end{pmatrix}\right)^T\\ \amp = \begin{pmatrix}-3 \amp 4 \\ -7 \amp 23/2 \\ -19 \amp 21\end{pmatrix}^T\\ \amp = \begin{pmatrix}-3 \amp -7 \amp -19 \\ 4 \amp 23/2 \amp 21 \end{pmatrix}. \end{align*}

Next

\begin{align*} B^TA^T \amp = \begin{pmatrix}-2 \amp -3 \\ 1/2 \amp 4 \end{pmatrix} \begin{pmatrix}0 \amp -1 \amp 2\\ 1 \amp 3 \amp 5\end{pmatrix} \\ \amp = \begin{pmatrix}-3 \amp -7 \amp -19 \\ 4 \amp 23/2 \amp 21 \end{pmatrix}. \end{align*}

Exercises Example Tasks

1.

Let

\begin{equation*} A = \begin{pmatrix} 3 \amp -1 \\ -2 \amp 2\end{pmatrix} \quad \mbox{ and } \quad B=\begin{pmatrix} 0 \amp 1 \\ 4 \amp -1 \end{pmatrix}. \end{equation*}
  1. Calculate \((A+B)^2\text{.}\)

  2. Calculate \(A^2 + 2AB + B^2\text{.}\)

2.

Let

\begin{equation*} E = \begin{pmatrix} 6 \amp 1 \\ -1 \amp 3 \\ -5 \amp 2\end{pmatrix} \quad \mbox{ and } \quad F=\begin{pmatrix} 1 \amp -2 \amp 0 \\ 3 \amp 1 \amp 4 \end{pmatrix}. \end{equation*}
  1. Calculate \((EF)_{23}\text{.}\)

  2. Calculate \((FE)_{12}\text{.}\)