1.3. Matrix multiplication#

We saw in the previous section that we can perform the arithmetic operations of addition, subtraction and multiplication by a scalar on matrices. Here we will look at multiplication of two matrices.

Definition 1.6 (Matrix multiplication)

Let \(A\) be an \(m \times n\) matrix and \(B\) a \(p \times q\) matrix, the product \(AB\) is defined as

(1.4)#\[ [AB]_{ij} = \sum_{k=1}^n a_{ik}b_{kj}. \]

The product \(AB\) is only defined if the number of columns in the first matrix is the same as the number of rows in the second matrix, i.e., \(n = p\), and the resulting matrix has the same number of rows as the first matrix and the same number of columnbs of the second matrix, i.e., a \(m \times q\) matrix.

The technique used to multiply two matrices together requires us to move across the horizontal rows of the first matrix (the \(i\) index) and down the vertical columns of the second matrix (the \(j\) index). We multiply corresponding elements together and sum the result. For example, consider the multiplication of the two \(2\times 2\) matrices \(A\) and \(B\) given below

\[\begin{split} \begin{align*} A &= \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, & B &= \begin{pmatrix} 5 & 6 \\ 7 & 8 \end{pmatrix}. \end{align*} \end{split}\]

The first thing we need to do is check whether matrix multiplication is defined for these matrices. An easy way to do this is to write the dimensions of the matrix underneath, e.g.,

\[\begin{split} \begin{align*} AB = \underset{2 \times \textcolor{red}{2}}{\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}} \underset{\textcolor{red}{2} \times 2}{\begin{pmatrix} 5 & 6 \\ 7 & 8 \end{pmatrix}}. \end{align*} \end{split}\]

Here the two inside numbers are the same so this matrix multiplication is defined. Futhermore the dimensions of the product of these two matrices is given by the two outside numbers. Using equation (1.4), to calculate \([AB]_{11}\) we have \(i=1\) and \(j=1\) so move through the elements from row 1 of \(A\) and column 1 of \(B\), multiplying the corresponding values and summing the result

\[ [AB]_{11} = a_{11}b_{11} + a_{12}b_{21} = 1(5) + 2(7) = 5 + 14 = 19. \]

So we have

\[\begin{split} \begin{align*} \begin{pmatrix} \textcolor{blue}{1} & \textcolor{blue}{2} \\ \textcolor{lightgray}{3} & \textcolor{lightgray}{4} \end{pmatrix} \begin{pmatrix} \textcolor{red}{5} & \textcolor{lightgray}{6} \\ \textcolor{red}{7} & \textcolor{lightgray}{8} \end{pmatrix} = \begin{pmatrix} \textcolor{blue}{1} (\textcolor{red}{5}) + \textcolor{blue}{2} (\textcolor{red}{7}) & \textcolor{lightgray}{\square} \\ \textcolor{lightgray}{\square} & \textcolor{lightgray}{\square} \end{pmatrix} = \begin{pmatrix} 5 + 14 & \textcolor{lightgray}{\square} \\ \textcolor{lightgray}{\square} & \textcolor{lightgray}{\square} \end{pmatrix} = \begin{pmatrix} 19 & \textcolor{lightgray}{\square} \\ \textcolor{lightgray}{\square} & \textcolor{lightgray}{\square} \end{pmatrix}. \end{align*} \end{split}\]

Moving across the top row we then need to calculate the value of \([AB]_{12}\). Now \(i = 1\) and \(j = 2\) so we multiply the values from row 1 of \(A\) and column 2 of \(B\) and sum the result

\[ [AB]_{12} = a_{11}b_{12} + a_{12}b_{22} = 1(6) + 2(8) = 6 + 16 = 22. \]

So we have

\[\begin{split} \begin{align*} \begin{pmatrix} \textcolor{blue}{1} & \textcolor{blue}{2} \\ \textcolor{lightgray}{3} & \textcolor{lightgray}{4} \end{pmatrix} \begin{pmatrix} \textcolor{lightgray}{5} & \textcolor{red}{6} \\ \textcolor{lightgray}{7} & \textcolor{red}{8} \end{pmatrix} = \begin{pmatrix} 19 & \textcolor{blue}{1} (\textcolor{red}{6}) + \textcolor{blue}{2} (\textcolor{red}{8}) \\ \textcolor{lightgray}{\square} & \textcolor{lightgray}{\square} \end{pmatrix} = \begin{pmatrix} 19 & 6 + 16 \\ \textcolor{lightgray}{\square} & \textcolor{lightgray}{\square} \end{pmatrix} = \begin{pmatrix} 19 & 22 \\ \textcolor{lightgray}{\square} & \textcolor{lightgray}{\square} \end{pmatrix}. \end{align*} \end{split}\]

Now that we have finished the first row of \(AB\) we now move down to the second row and back to the first column to calculate \([AB]_{21}\). Now \(i = 2\) and \(j = 1\) so we multiply the values from row 2 of \(A\) and column 1 of \(B\) and sum the result

\[[AB]_{21} = a_{21} b_{11} + a_{22} b_{21} = 3(5) + 4(7) = 15 + 28 = 43.\]

So we have

\[\begin{split} \begin{align*} \begin{pmatrix} \textcolor{lightgray}{1} & \textcolor{lightgray}{2} \\ \textcolor{blue}{3} & \textcolor{blue}{4} \end{pmatrix} \begin{pmatrix} \textcolor{red}{5} & \textcolor{lightgray}{6} \\ \textcolor{red}{7} & \textcolor{lightgray}{8} \end{pmatrix} = \begin{pmatrix} 19 & 22 \\ \textcolor{blue}{3} (\textcolor{red}{5}) + \textcolor{blue}{4} (\textcolor{red}{7}) & \textcolor{lightgray}{\square} \end{pmatrix} = \begin{pmatrix} 19 & 22 \\ 15 + 28 & \textcolor{lightgray}{\square} \end{pmatrix} = \begin{pmatrix} 19 & 22 \\ 43 & \textcolor{lightgray}{\square} \end{pmatrix}. \end{align*} \end{split}\]

Moving across we now need to calculate the final element \([AB]_{22}\). Now \(i = 2\) and \(j = 2\) so we multiply the values from row 2 of \(A\) and column 2 of \(B\) and sum the result

\[[AB]_{22} = a_{21} b_{12} + a_{22} b_{22} = 3(6) + 4(8) = 18 + 32 = 50.\]

So we have

\[\begin{split} \begin{align*} \begin{pmatrix} \textcolor{lightgray}{1} & \textcolor{lightgray}{2} \\ \textcolor{blue}{3} & \textcolor{blue}{4} \end{pmatrix} \begin{pmatrix} \textcolor{lightgray}{5} & \textcolor{red}{6} \\ \textcolor{lightgray}{7} & \textcolor{red}{8} \end{pmatrix} = \begin{pmatrix} 19 & 22 \\ 43 & \textcolor{blue}{3} (\textcolor{red}{6}) + \textcolor{blue}{4} (\textcolor{red}{8}) \end{pmatrix} = \begin{pmatrix} 19 & 22 \\ 43 & 18 + 32 \end{pmatrix} = \begin{pmatrix} 19 & 22 \\ 43 & 50 \end{pmatrix}. \end{align*} \end{split}\]
Arthur Cayley

Fig. 1.1 Arthur Cayley (1821 - 1895)#

This method of multiplying matrices together may seem unnecessarily convoluted when first encountered. The reason we perform matrix multiplication in this way is because English mathematician Arthur Cayley found that it allows for a convenient way to represent composite linear transformations which we will study towards the end of the semester.

Example 1.6

Given the matrices

\[\begin{split} \begin{align*} A &= \begin{pmatrix} 1 & 0 \\ -2 & 3 \end{pmatrix}, & B &= \begin{pmatrix} 2 & 3 \\ 1 & 5 \end{pmatrix}, \\ C &= \begin{pmatrix} 1 & 1 & 0 \\ 3 & -2 & 1 \end{pmatrix}, & D &= \begin{pmatrix} 1 \\ 3 \end{pmatrix}. \end{align*} \end{split}\]

calculate the following (where possible):

(i)   \(AB\)

Solution
\[\begin{split} \begin{align*} AB &= \begin{pmatrix} 1 & 0 \\ -2 & 3 \end{pmatrix} \begin{pmatrix} 2 & 3 \\ 1 & 5 \end{pmatrix} \\ &= \begin{pmatrix} 1(2) + 0(1) & 1(3) + 0(5)\\ -2(2) + 3(1) & -2(3) + 3(5) \end{pmatrix} \\ &= \begin{pmatrix} 2 + 0 & 3 + 0 \\ -4 + 3 & -6 + 15\end{pmatrix} \\ &= \begin{pmatrix} 2 & 3 \\ -1 & 9 \end{pmatrix} \end{align*} \end{split}\]

(ii)   \(BC\)

Solution
\[\begin{split} \begin{align*} BC &= \begin{pmatrix} 2 & 3 \\ 1 & 5 \end{pmatrix} \begin{pmatrix} 1 & 1 & 0 \\ 3 & -2 & 1 \end{pmatrix} \\ &= \begin{pmatrix} 2(1) + 3(3) & 2(1) + 3(-2) & 2(0) + 3(1) \\ 1(1) + 5(3) & 1(1) + 5(-2) & 1(0) + 5(1) \end{pmatrix} \\ &= \begin{pmatrix} 2+9 & 2-6 & 0+3 \\ 1+15 & 1-10 & 0+5 \end{pmatrix} \\ &= \begin{pmatrix}11 & -4 & 3 \\ 16 & -9 & 5 \end{pmatrix} \end{align*} \end{split}\]

(iii)   \(CD\)

Solution

\(CD\) is undefined since \(C\) has 3 columns and \(D\) only has 2 rows.

(iv)   \(CC^\mathsf{T}\)

Solution
\[\begin{split}\begin{align*} CC^\mathsf{T} &= \begin{pmatrix} 1 & 1 & 0 \\ 3 & -2 & 1 \end{pmatrix} \begin{pmatrix} 1 & 3 \\ 1 & -2 \\ 0 & 1 \end{pmatrix} \\ &= \begin{pmatrix} 1(1) + 1(1) + 0(0) & 1(3) + 1(-2) + 0(1) \\ 3(1) + (-2)(1) + 1(0) & 3(3) + (-2)(-2) + 1(1) \end{pmatrix} \\ &= \begin{pmatrix} 1 + 1 + 0 & 3 - 2 + 0 \\ 3 - 2 + 0 & 9 + 4 + 1 \end{pmatrix} \\ &= \begin{pmatrix} 2 & 1 \\ 1 & 14 \end{pmatrix} \end{align*} \end{split}\]

Theorem 1.4 (Properties of matrix multiplication)

The following properties hold for matrix multiplication

  • Matrix multiplication is not commutative: \(AB \neq BA\)

  • Associative law: \(A(BC) = (AB)C\)

  • Left distributive law: \(A(B + C) = AB + AC\)

  • Right distributive law: \((A + B)C = AC + BC\)

  • Transpose of a product: \((AB)^\mathsf{T} = B^\mathsf{T}A^\mathsf{T}\)

1.3.1. Matrix exponents#

Just like with scalar quantities we can calculate the exponent of a number \(a^n\) by multiplying by itself \(n\) times, i.e., \(a^3 = a \cdot a \cdot a\), we can also do this for square matrices that have the same number of rows and columns.

Definition 1.7 (Matrix exponents)

Let \(A\) be a square \(n \times n\) matrix. Then we write \(A^2=AA\) and more generally:

(1.5)#\[ \begin{align*} A^n = \underbrace{A A \cdots A}_{n \textsf{ times}}. \end{align*} \]

Example 1.7

Given the matrix

\[\begin{split} A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, \end{split}\]

evaluate:

(i)   \(A^2\)

Solution
\[\begin{split} \begin{align*} A^2 = AA &= \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} \\ &= \begin{pmatrix} 1 + 6 & 2 + 8 \\ 3 + 12 & 6 + 16 \end{pmatrix} \\ &= \begin{pmatrix} 7 & 10 \\ 15 & 22 \end{pmatrix} \end{align*} \end{split}\]

(ii)   \(A^3\)

Solution
\[\begin{split} \begin{align*} A^3 = AA^2 &= \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} \begin{pmatrix} 7 & 10 \\ 15 & 22 \end{pmatrix} \\ &= \begin{pmatrix} 7 + 30 & 10 + 44 \\ 21 + 60 & 30 + 88 \end{pmatrix} \\ &= \begin{pmatrix} 37 & 54 \\ 81 & 118 \end{pmatrix} \end{align*} \end{split}\]

(iii)   \(A^5\)

Solution
\[\begin{split} \begin{align*} A^5 = A^2A^3 &= \begin{pmatrix} 7 & 10 \\ 15 & 22 \end{pmatrix} \begin{pmatrix} 37 & 54 \\ 81 & 118 \end{pmatrix} \\ &= \begin{pmatrix} 259 + 810 & 378 + 1180 \\ 555 + 1782 & 810 + 2596 \end{pmatrix} \\ &= \begin{pmatrix} 1069 & 1558 \\ 2337 & 3406 \end{pmatrix} \end{align*} \end{split}\]