Tutorials on Advanced Math and Computer Science Concepts

# Matrix Multiplication

We discussed that scalar multiplication applies to matrices by multiplying the scalar by each component in the matrix. In order to compute transformations, we also need to be able to multiply two matrices together. This operation will be slightly more complex compared to the others we have seen so far, but after a few examples, it will seem more natural.

Matrix multiplication involves taking the dot product of the rows of one matrix by the columns of another matrix. Suppose we wanted to multiply two matrices, A and B. Let's define $A = \left[\begin{array}{cc} 2 & 3 & 0 & 1 \\ 4 & -1 & 2 & -1 \end{array}\right]$ and $B = \left[\begin{array}{cc} 3 & 1 \\ 1 & 2 \\ 2 & 3 \\ 0 & 5 \end{array}\right]$. To multiply A by B, we are going to dot product all the rows in matrix A by the columns in matrix B.

To start, let's take the first row in A, $\left[\begin{array}{cc} 2 & 3 & 0 & 1 \end{array}\right]$. We will dot product this by the first column in B, $\left[\begin{array}{cc} 3 \\ 1 \\ 2 \\ 0 \end{array}\right]$. Doing this would give us: $2*3 + 3*1 + 2*0 + 1*0 = 9$. This means that the first component in our answer is equal to 9. We will repeat this process with the remaining rows and columns as shown below.

$\left[\begin{array}{cc} 2 & 3 & 0 & 1 \end{array}\right] * \left[\begin{array}{cc} 3 \\ 1 \\ 2 \\ 0 \end{array}\right] = 9$

$\left[\begin{array}{cc} 2 & 3 & 0 & 1 \end{array}\right] * \left[\begin{array}{cc} 1 \\ 2 \\ 3 \\ 5 \end{array}\right] = 13$

$\left[\begin{array}{cc} 4 & -1 & 2 & -1 \end{array}\right] * \left[\begin{array}{cc} 3 \\ 1 \\ 2 \\ 0 \end{array}\right] = 15$

$\left[\begin{array}{cc} 4 & -1 & 2 & -1 \end{array}\right] * \left[\begin{array}{cc} 1 \\ 2 \\ 3 \\ 5 \end{array}\right] = 3$

This tells us that $AB = \left[\begin{array}{cc} 9 & 13 \\ 15 & 3 \end{array}\right]$. To discuss this more formally, let's define the resulting matrix from the multiplication as R. The value of $R_{11}$ is the first row of A dot product the first column of B. The value of $R_{12}$ is the first row of A dot product the second column of B. This pattern continues until we have multiplied all the rows and columns.

One thing to keep in mind is that this operation only works if the number of rows in the first matrix is equal to the number of columns in the second matrix.  If this isn't true, we wouldn't be able to successfully take the dot product, due to a mismatch in the number of elements. Knowing this, we can explore some additional theories related to matrix multiplication.

Theorem: Suppose that A, B, and C are matrices that can be multiplied together, and t is a real number scalar. The following statements are true.

1. A(B+C) = AB + AC
2. (A+B)C = AC + BC
3. t(AB) = (tA)B = A(tB)
4. A(BC) = (AB)C
5. $(AB)^T = B^TA^T$

One important note to make about matrix multiplication is that it is not communitive. If we reverse the order of matrix multiplication, the result is not guaranteed to be the same.