index

## Matrix Multiplication

Here's a small tutorial on how to perform matrix multiplication.

### Dot Product

Before we begin let's first review how we can perform a dot product.

Given 2 vectors $\vec{a}$ , and $\vec{b}$ , we can find the dot product $\vec{a} \cdot \vec{b}$ with the following:

Notice that the dot product is a scalar value.

For example:

We can use this technique to perform matrix multiplication.

### Matrix Multiplication

Given two matrices $\boldsymbol{A}$, and $\boldsymbol{B}$, they can be multiplied to a matrix, $\boldsymbol{C}$ if the first matrix's number of columns is the same as the second matrix's number of rows.

This means that if we have a matrix dimensions of $m \times n$, it can be mulitplied by a second matrix if it has dimensions of $n \times p$.

For example given a matrix $\boldsymbol{A}$ with dimensions of $3 \times 3$, and matrix $\boldsymbol{B}$ of dimensions $3 \times 4$, it satisfies the conditions that the dimensions of the matrices are valid for matrix multiplication.

We can then visualize the matrix multiplication of $\boldsymbol{A} * \boldsymbol{B}$ as taking every row in $\boldsymbol{A}$, as a vector $\vec{v_i}$ , and finding the dot product of every column in $\boldsymbol{B}$, as a column vector $\vec{u_i}$.

This will be the single element in the matrix $\boldsymbol{C}$ located at position $(0, 0)$. Then, to find $\boldsymbol{C_{0,1}}$, it will just be:

We can then repeat the process until we have completed matrix $\boldsymbol{C}$.

### Other Notes

• Matrix multiplication is anti-commutative. So, the order matters here in evaluation. Multiplying matrices $\boldsymbol{A}$, and $\boldsymbol{B}$ as $\boldsymbol{A} * \boldsymbol{B}$ is not the same as $\boldsymbol{B} * \boldsymbol{A}$.