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}\), \(\vec{b}\), we can find the dot product \(\vec{a}\) \(\cdot\) \(\vec{b}\) with the following:
$$ \vec{a} = \begin{bmatrix} a_{x} & a_{y} & a_{z} \end{bmatrix} $$ $$ \vec{b} = \begin{bmatrix} b_{x} & b_{y} & b_{z} \end{bmatrix} $$ $$ \vec{a} \cdot \vec{b} = a_{x}b_{x} + a_{y}b_{y} + a_{z}b_{z} $$
Notice that the dot product is a scalar value.
For example:
$$ \vec{a} = \begin{bmatrix} 8 & 10 & 4 \end{bmatrix} $$ $$ \vec{b} = \begin{bmatrix} 2 & 3 & 9 \end{bmatrix} $$
$$
\begin{align}
\vec{a} \cdot \vec{b} &= (8 \times 2) + (10 \times 3) + (4 \times 9) \\
&= 16 + 30 + 36 \\
&= 82
\end{align}
$$
Matrix Multiplication
Given two matrices \(\bf{A}\), and \(\bf{B}\), they can be multiplied to a matrix, 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 \(\it{m} \times \it{n}\), it can be mulitplied by a second matrix if it has dimensions of \(\it{n} \times \it{p}\).
For example given a matrix \(\bf{A}\) with dimensions of \(3 \times 3\), and matrix \(\bf{B}\) of dimensions \(3 \times 4\), it satisfies the conditions that the dimensions of the matrices are valid for matrix multiplication.
$$
\bf{A} = \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix} \\
\bf{B} = \begin{bmatrix} j & k & l & m \\ o & p & q & r \\ s & t & u & v \end{bmatrix}
$$
We can then visualize the matrix multiplication \(\bf{A}\bf{B}\) of as taking every row in \(\bf{A}\), as a vector \(\vec{v}_{i}\), and finding the dot product of every column in \(\bf{B}\), as a column vector \(\vec{u}_{i}\).
$$ \vec{v}_{0} = \begin{bmatrix} a & b & c \end{bmatrix} $$ $$ \vec{u}_{0} = \begin{bmatrix} j \\ o \\ s \end{bmatrix} $$ $$ \vec{v}_{i} \cdot \vec{u}_{i} = (a * j) + (b * o) + (c * s) $$
This will be the single element in the matrix \(\bf{C}\) located at position \(0, 0\). Then, to find \(\bf{C_{0,1}}\), it will just be:
$$
\begin{align}
\vec{v}_{0} \cdot \vec{u}_{1} &= \begin{bmatrix} a & b & c \end{bmatrix} * \begin{bmatrix} k \\ p \\ t \end{bmatrix} \\
&= (a * k) + (b * p) + (c * t)
\end{align}
$$
We can then repeat the process until we have completed matrix \(\bf{C}\).
Other Notes
- Matrix multiplication is anti-commutative. So, the order matters here in evaluation. Multiplying matrices \(\bf{A}\), and \(\bf{B}\) as \(\bf{AB}\) is not the same as \(\bf{BA}\).