Math Insight

Matrix and vector multiplication examples

Example 1

Compute $A \vc{x}$ where $\vc{x} = (-2, 1, 0)$ and \begin{align*} A= \left[ \begin{array}{rrr} 1 &2 &3\\ 4 &5 &6\\ 7 &8 &9\\ 10 & 11 & 12 \end{array} \right]. \end{align*}

Solution: \begin{align*} A\vc{x} &=\left[ \begin{array}{rrr} 1 &2 &3\\ 4 &5 &6\\ 7 &8 &9\\ 10 & 11 & 12 \end{array} \right] \left[ \begin{array}{r} -2\\ 1\\ 0 \end{array} \right] \\ &= \left[ \begin{array}{c} -2\cdot 1 + 1 \cdot 2 + 0 \cdot 3\\ -2\cdot 4 + 1 \cdot 5 + 0 \cdot 6\\ -2\cdot 7 + 1 \cdot 8 + 0 \cdot 9\\ -2\cdot 10 + 1 \cdot 11 + 0 \cdot 12 \end{array} \right] \\ &= \left[ \begin{array}{c} 0\\ -3\\ -6\\ -9 \end{array} \right] = (0, -3, -6, -9). \end{align*}

Example 2

Compute $A \vc{y}$ where $\vc{y} = (-3, -2, -1, 0)$ and $A$ is as in Example 1.

Solution: The matrix-vector product is not defined. $A$ is $4 \times 3$ and $\vc{y}$ is $4 \times 1$ (viewed as column vector).

Example 3

Compute $BC$, where \begin{align*} B= \left[ \begin{array}{rrr} 1 &2 &3\\ 4 &5 &6 \end{array} \right] \qquad \text{and} \qquad C= \left[ \begin{array}{rr} 1 &2\\ 3 & 4\\ 5 &6 \end{array} \right]. \end{align*}

Solution: \begin{align*} BC &= \left[ \begin{array}{rrr} 1 &2 &3\\ 4 &5 &6 \end{array} \right] \left[ \begin{array}{rr} 1 &2\\ 3 & 4\\ 5 &6 \end{array} \right] \\ &= \left[ \begin{array}{ccc} 1\cdot 1 + 2\cdot 3 + 3\cdot 5 && 1\cdot 2 + 2\cdot 4 + 3\cdot 6 \\ 4\cdot 1 +5\cdot 3 +6\cdot 5 && 4\cdot 2 +5\cdot 4 +6\cdot 6 \end{array} \right] \\ &= \left[ \begin{array}{cc} 22 & 28\\ 49 & 64 \end{array} \right] \end{align*}

Example 4

Using $B$ and $C$ as defined in Example 3, calculate $CB$.

Solution: \begin{align*} CB &= \left[ \begin{array}{rr} 1 &2\\ 3 & 4\\ 5 &6 \end{array} \right] \left[ \begin{array}{rrr} 1 &2 &3\\ 4 &5 &6 \end{array} \right] \\ &= \left[ \begin{array}{ccccc} 1\cdot 1 + 2\cdot 4 &&1\cdot 2 + 2\cdot 5 &&1\cdot 3 + 2\cdot 6\\ 3\cdot 1 + 4\cdot 4 &&3\cdot 2 + 4\cdot 5 &&3\cdot 3 + 4\cdot 6\\ 5\cdot 1 + 6\cdot 4 &&5\cdot 2 + 6\cdot 5 &&5\cdot 3 + 6\cdot 6 \end{array} \right] \\ &= \left[ \begin{array}{rrr} 9 & 12 & 15\\ 19 & 26 & 33\\ 29 & 40 & 51 \end{array} \right] \end{align*} Clearly, one can see that matrix multiplication is not commutative, i.e., $BC \ne CB$. In the case of examples 3 and 4, $BC$ isn't even the same size matrix as $CB$. In some other cases, $BC$ might be defined but $CB$ won't be defined (for example, when $B$ is a $3 \times 2$ matrix and $C$ is a $2 \times 4$ matrix). It is even true that when $B$ and $C$ are square matrices, matrix multiplication is not commutative. You can try yourself and see that $BC \ne CB$ if \begin{align*} B= \left[ \begin{array}{rr} 1 &2\\ 3 & 4 \end{array} \right] \qquad \text{and} \qquad C= \left[ \begin{array}{rr} 5 &6\\ 7 & 8 \end{array} \right]. \end{align*}