Skip to main content

Section 2.1 matrix-matrix products

Subsection 2.1.1 Matrix-matrix products

Matrix matrix multiplication is an extension of matrix vector multiplication in the following way. As long as the number of columns of \(A\) matches the number of rows of \(C\text{,}\) the product \(AC\) can be computed.

Definition 2.1.1. Matrix-matrix multiplication.

Given matrices \(A\) and \(C\text{,}\) we form their product \(AC\) by first writing \(C\) in terms of its columns
\begin{equation*} C =\left[\begin{array}{rrrr} \cvec_1 \amp \cvec_2 \amp \cdots \amp \cvec_p \end{array}\right] \end{equation*}
and then defining
\begin{equation*} AC = \left[\begin{array}{rrrr} A\cvec_1 \amp A\cvec_2 \amp \cdots \amp A\cvec_p \end{array}\right]. \end{equation*}
Suppose \(A\) has 3 rows and \(C \) has 2 columns. Then
\begin{equation*} AC = \left[\begin{array}{rrrr} A\cvec_1 \amp A\cvec_2 \end{array}\right]. \end{equation*}
Since each column of the product \(AC\) is a matrix vector product, we can also view \(AC\) in terms of dot products. That is letting by viewing rows of the matrix \(A\) as vectors; call the first row \(\rvec_1\text{,}\) and the second row \(\rvec_2\text{.}\) We have that the matrix vector product \(A\cvec_1=\left[\begin{array}{r}\rvec_1 \cdot \cvec_1 \\ \rvec_2\cdot \cvec_1 \\ \rvec_3 \cdot \cvec_1 \\ \end{array}\right]\) Similarly the matrix vector product \(A\cvec_2=\left[\begin{array}{r}\rvec_1 \cdot \cvec_2 \\ \rvec_2\cdot \cvec_2 \\ \rvec_3 \cdot \cvec_2 \\ \end{array}\right]\)
Since
\begin{equation*} AC = \left[\begin{array}{rrrr} A\cvec_1 \amp A\cvec_2 \end{array}\right]. \end{equation*}
We have that
\begin{equation*} AC= \left[\begin{array}{rr} \rvec_1 \cdot \cvec_1 \amp \rvec_1 \cdot \cvec_2 \\ \rvec_2 \cdot \cvec_1 \amp \rvec_2 \cdot \cvec_2 \\ \rvec_3 \cdot \cvec_1 \amp \rvec_3 \cdot \cvec_2 \\ \end{array}\right]. \end{equation*}
Therefore in terms of dot products, the entry in the first row, first column of \(AC\) is the dot product \(\rvec_1\cdot \cvec_1\text{,}\) the entry in the second row, first column is the dot product \(\rvec_2\cdot \cvec_1\text{,}\) the entry in the 3rd row first column is the dot product \(\rvec_3\cdot \cvec_1\text{.}\) Moving to the second column, we have the entry in the the first row second column is the the dot product \(\rvec_1\cdot \cvec_2\text{,}\) the entry in the second row, second column is the dot product \(\rvec_2\cdot \cvec_2\text{,}\) the entry in the 3rd row second column is just the dot product \(\rvec_3\cdot \cvec_2\text{.}\)

Activity 2.1.1.

Consider the matrices
\begin{equation*} A = \left[\begin{array}{rrr} 1 \amp 3 \amp 2 \\ -3 \amp 4 \amp -1 \\ \end{array}\right],~~~ C = \left[\begin{array}{rr} 3 \amp 0 \\ 1 \amp 2 \\ -2 \amp -1 \\ \end{array}\right]\text{.} \end{equation*}
  1. Before computing, first explain why the shapes of \(A\) and \(C\) enable us to form the product \(AC\text{.}\) Then describe the shape of \(AC\text{.}\)
  2. Compute the product \(AC\text{.}\)
  3. Sage can multiply matrices using the * operator. Define the matrices \(A\) and \(B\) in the Sage cell below and check your work by computing \(AB\text{.}\)
  4. Are we able to form the matrix product \(BA\text{?}\) If so, use the Sage cell above to find \(BA\text{.}\) Is it generally true that \(AB = BA\text{?}\)
  5. Suppose we form the three matrices.
    \begin{equation*} A = \left[\begin{array}{rr} 4 \amp 0 \\ 10 \amp 0 \\ \end{array}\right], B = \left[\begin{array}{rr} 1 \amp 1\\ 5 \amp -1 \\ \end{array}\right], C = \left[\begin{array}{rr} 2 \amp 0 \\ 0 \amp 3 \\ \end{array}\right]\text{.} \end{equation*}
    Compute the folowing produts by hand: \(AB\text{,}\) \(BA\text{,}\) \(AC\text{,}\) \(CA\text{,}\) \(CB\text{,}\)\(BC\text{,}\) \(CC\text{,}\) and \(CCC\text{.}\) Use Sage to checck your answers
  6. Compare the results of evaluating \(A(BC)\) and \((AB)C\) and state your finding as a general principle.
  7. When we are dealing with real numbers, we know if \(a\neq 0\) and \(ab = ac\text{,}\) then \(b=c\text{.}\) Define matrices
    \begin{equation*} A = \left[\begin{array}{rr} 1 \amp 2 \\ -2 \amp -4 \\ \end{array}\right], B = \left[\begin{array}{rr} 3 \amp 0 \\ 1 \amp 3 \\ \end{array}\right], C = \left[\begin{array}{rr} 1 \amp 2 \\ 2 \amp 2 \\ \end{array}\right] \end{equation*}
    and compute \(AB\) and \(AC\text{.}\)
    If \(AB = AC\text{,}\) is it necessarily true that \(B = C\text{?}\)
  8. Again, with real numbers, we know that if \(ab = 0\text{,}\) then either \(a = 0\) or \(b=0\text{.}\) Define
    \begin{equation*} A = \left[\begin{array}{rr} 1 \amp 2 \\ -2 \amp -4 \\ \end{array}\right], B = \left[\begin{array}{rr} 2 \amp -4 \\ -1 \amp 2 \\ \end{array}\right] \end{equation*}
    and compute \(AB\text{.}\)
    If \(AB = 0\text{,}\) is it necessarily true that either \(A=0\) or \(B=0\text{?}\)
Answer.
  1. The product \(AB\) exists because the number of columns of \(A\) equals the number of rows of \(B\text{.}\) The dimensions of \(AB\) are \(2\times 2\text{.}\)
  2. We have \(AB = \left[\begin{array}{rr} 2 \amp 4 \\ -3 \amp 9 \end{array}\right] \text{.}\)
  3. Define
    A = matrix(2, 3, [1, 3, 2, -3, 4, -1])
    B = matrix(3, 2, [3, 0, 1, 2, -2, -1])
    A*B
          
  4. It is not generally true that \(AB=BA\text{.}\)
  5. We find that \(A(B+C)=AB + AC\text{.}\)
  6. We find that \(A(BC) = (AB)C\text{.}\)
  7. It is not generally true that \(B=C\) if \(AB=AC\text{.}\)
  8. It is not generally true that \(A=0\) or \(B=0\) if \(AB=0\text{.}\)
Solution.
  1. The product \(AB\) exists because the number of columns of \(A\) equals the number of rows of \(B\text{.}\) The dimensions of \(AB\) are \(2\times 2\text{.}\)
  2. We have \(AB = \left[\begin{array}{rr} 2 \amp 4 \\ -3 \amp 9 \end{array}\right] \text{.}\)
  3. Define
    A = matrix(2, 3, [1, 3, 2, -3, 4, -1])
    B = matrix(3, 2, [3, 0, 1, 2, -2, -1])
    A*B
          
  4. Yes, we can form the product \(BA\) because the number of columns of \(B\) equals the number of rows of \(A\text{.}\) This product \(AB\) will be \(3\times3\text{,}\) however, so it must be true that \(AB\neq BA\text{.}\)
  5. We find that \(A(B+C)=AB + AC\text{.}\)
  6. We find that \(A(BC) = (AB)C\text{.}\)
  7. It is not generally true that \(B=C\) if \(AB=AC\text{,}\) as illustrated by this example.
  8. It is not generally true that \(A=0\) or \(B=0\) if \(AB=0\text{,}\) as illustrated by this example.