# Matrix Multiplication

### WHAT NEEDS TO HOLD

Matrix multiplication is quite different from what you might expect. You do NOT simply multiply corresponding entries multiply corresponding entries in the two matrices... it's a bit more complicated. Because of this there's an important condition that must hold: when finding the product of $$AB$$, the number of columns in $$A$$, must equal the number of rows in $$B$$ (the reason for this will make more sense once you learn the technique below). The resulting matrix will have the same number of rows as $$A$$ and the same number of columns as $$B$$ (i.e., if you multiply an $$m \times n$$ times an $$n \times p$$ matrix you will get a matrix of size $$m \times p$$.

Example: Let's say we have 3 different matrices: $$A$$, which is $$3 \times 5$$, $$B$$ which is $$2 \times 3$$ and $$C$$ which is $$4 \times 3$$. Which of the following are defined: $$AB , BA, BC, CA$$? If it is defined what size will it be?

Solution

$$AB$$ means we multiply a $$3 \times 5$$ by a $$2 \times 3$$. Since the number of rows in $$B$$ is 2 while the number of columns in $$A$$ is 5 the multiplication is NOT possible.

$$BA$$ means we multiply a $$2 \times 3$$ by a$$3 \times 5$$. Since the number of rows in $$A$$ is 3 while the number of columns in $$B$$ is 3 the multiplication is possible. The size of $$BA$$ is $$2 \times 5$$.

$$BC$$ means we multiply a $$2 \times 3$$ by a $$4 \times 3$$. Since the number of rows in $$C$$ is 4 while the number of columns in $$B$$ is 3 the multiplication is NOT possible.

$$CA$$ means we multiply a $$4 \times 3$$ by a $$3 \times 5$$. Since the number of rows in $$A$$ is 3 while the number of columns in $$C$$ is 3 the multiplication is possible. The size of $$CA$$ is $$4 \times 5$$.

### HOW TO MULTIPLY MATRICES

As already mentioned , the technique might not be so intuitive. Here's what to do: If you have two matrices $$A$$ and $$B$$ and you want to obtain a new matrix $$C = AB$$, to get the entry $$c_{ij}$$, you multiply each entry in row $$i$$ of matrix $$A$$ by the corresponding entry in column $$j$$ of matrix $$B$$ and add them up.
e.g. if we multiply $$2 \times 2$$ matrices and we want to find entry $$c_{21}$$, we multiply entries in the 2nd of
$$A$$ by those in the 1st column of $$B$$ and add up the results.

$$\text{i.e.} \quad c_{21} = a_{21}b_{11} + a_{22}b_{21}$$

e.g. to get $$c_{21}$$ we have: $\begin{bmatrix} a_{11} & a_{12} \\ \colorbox{yellow}{a_{21}} & \colorbox{yellow}{a_{22}}\\ \end{bmatrix} \begin{bmatrix} \colorbox{yellow}{b_{11}} & b_{12} \\ \colorbox{yellow}{b_{21}}& b_{22} \\ \end{bmatrix}$

To find $$c_{11}$$: $$\begin{bmatrix} \colorbox{yellow}{a_{11}} & \colorbox{yellow}{a_{12}} \\ a_{21} & a_{22}\\ \end{bmatrix} \begin{bmatrix} \colorbox{yellow}{b_{11}} & b_{12} \\ \colorbox{yellow}{b_{21}}& b_{22} \\ \end{bmatrix}$$

To find $$c_{12}$$: $$\begin{bmatrix} \colorbox{yellow}{a_{11}} & \colorbox{yellow}{a_{12}} \\ a_{21} & a_{22}\\ \end{bmatrix} \begin{bmatrix} b_{11} & \colorbox{yellow}{b_{12}} \\ b_{21}& \colorbox{yellow}{b_{22}} \\ \end{bmatrix}$$

To find $$c_{22}$$: $$\begin{bmatrix} a_{11} & a_{12} \\ \colorbox{yellow}{a_{21}} & \colorbox{yellow}{a_{22}}\\ \end{bmatrix} \begin{bmatrix} b_{11} & \colorbox{yellow}{b_{12}} \\ b_{21}& \colorbox{yellow}{b_{22}} \\ \end{bmatrix}$$

Example : If $$A = \begin{bmatrix} 3 & 5 \\ -1 & 0 \\ \end{bmatrix}$$ and $$B = \begin{bmatrix} 4 & -6 \\ 2 & 1 \\ \end{bmatrix}$$ find $$AB$$.

Solution:
$\begin{split} AB & = \begin{bmatrix} (3)(4) + (5)(2) & (3)(-6) + (5)(1) \\ (-1)(4) + (0)(2) & (-1)(-6) + (0)(1) \\ \end{bmatrix} \\ & = \begin{bmatrix} 22 & -13 \\ -4 & 6 \\ \end{bmatrix} \\ \end{split}$

Example: If $$A = \begin{bmatrix} 5 & -1 \\ 6 & 2 \\ 0 & 1 \\ \end{bmatrix}$$ and $$B = \begin{bmatrix} 5 & 1 \\ -7 & 2 \\ \end{bmatrix}$$ find $$AB$$.

Solution: Since $$A$$ is $$3 \times 2$$ and $$B$$ is $$2 \times 2$$, we are able to do multiplication and
$$AB$$ will be of the size $$3 \times 2$$.

$\begin{split} AB & = \begin{bmatrix} (5)(5) + (-1)(-7) & (5)(1) + (-1)(2) \\ (6)(5) + (2)(-7) & (6)(1) + (2)(2) \\ (0)(5) + (1)(-7) & (0)(1) + (1)(2) \\ \end{bmatrix} \\ & = \begin{bmatrix} 32 & 3 \\ 16 & 10 \\ -7 & 2 \\ \end{bmatrix} \\ \end{split}$

Example 1: 2x2

Example 2: 3x3

Example 3: 3x3 by 3x1

Example 4: 4x3 by 3x2