Skip to main content

Section 2.2 Matrix Multiplication

Subsection 2.2.1 Matrix Multiplication

Definition 2.2.1. Matrix Multiplication.

Let \(A\) and \(B\) be two matrices where:
\(A\) is an \(m \times n\) matrix:
\begin{equation*} A = \begin{pmatrix} a_{11} \amp a_{12} \amp a_{13} \amp \cdots \amp a_{1n} \\ a_{21} \amp a_{22} \amp a_{23} \amp \cdots \amp a_{2n} \\ a_{31} \amp a_{32} \amp a_{33} \amp \cdots \amp a_{3n} \\ \vdots \amp \vdots \amp \vdots \amp \ddots \amp \vdots \\ a_{m1} \amp a_{m2} \amp a_{m3} \amp \cdots \amp a_{mn} \end{pmatrix} \end{equation*}
\(B\) is an \(n \times p\) matrix:
\begin{equation*} B = \begin{pmatrix} b_{11} \amp b_{12} \amp b_{13} \amp \cdots \amp b_{1p} \\ b_{21} \amp b_{22} \amp b_{23} \amp \cdots \amp b_{2p} \\ b_{31} \amp b_{32} \amp b_{33} \amp \cdots \amp b_{3p} \\ \vdots \amp \vdots \amp \vdots \amp \ddots \amp \vdots \\ b_{n1} \amp b_{n2} \amp b_{n3} \amp \cdots \amp b_{np} \end{pmatrix} \end{equation*}
The matrix product \(AB\) is an \(m \times p\) matrix \(C = [c_{ij}]\) where each entry is defined by:
\begin{equation*} c_{ij} = \sum_{k=1}^{n} a_{ik} b_{kj} = a_{i1}b_{1j} + a_{i2}b_{2j} + a_{i3}b_{3j} + \cdots + a_{in}b_{nj} \end{equation*}
for \(i = 1, 2, \ldots, m\) and \(j = 1, 2, \ldots, p\text{.}\)

Example 2.2.2. Matrix Multiplication Example.

Let us compute the product of the following matrices:
\begin{equation*} A = \begin{pmatrix} 2 \amp -8 \amp 8 \\ -2 \amp 1 \amp 0 \\ 0 \amp -5 \amp 10 \end{pmatrix} \end{equation*}
and
\begin{equation*} B = \begin{pmatrix} 0 \amp 3 \amp -6 \amp 6 \amp 4 \amp -5 \\ 3 \amp -7 \amp 8 \amp -5 \amp 8 \amp 9 \\ 3 \amp -9 \amp 12 \amp -9 \amp 6 \amp 15 \end{pmatrix} \end{equation*}
Since \(A\) is \(3 \times 3\) and \(B\) is \(3 \times 6\text{,}\) the product \(AB\) will be a \(3 \times 6\) matrix.
Solution.
We can compute this using Sage:

Insight 2.2.3.

Understanding Matrix Multiplication: Matrix multiplication is not performed element-wise like addition. Instead, each entry \(c_{ij}\) of the product \(AB\) is the dot product of the \(i\)-th row of \(A\) with the \(j\)-th column of \(B\text{.}\)
Think of it this way: to find \(c_{23}\) (the entry in row 2, column 3), you take the second row of \(A\) and "walk along" the third column of \(B\text{,}\) multiplying corresponding elements and adding them up. This is why matrix multiplication requires the number of columns in the first matrix to equal the number of rows in the second matrix.
This seemingly complex rule has profound geometric meaning: matrix multiplication represents the composition of linear transformations. When you multiply two matrices, you’re creating a new transformation that combines the effects of both original transformations. This is why matrix multiplication is so central to linear algebra and its applications in physics, computer graphics, and data science.

Checkpoint 2.2.4. Computing a Single Entry.

For the matrices \(A\) and \(B\) given above, compute only the entry \((AB)_{23}\) (the entry in row 2, column 3) using a loop or direct calculation.
Hint.
Remember that \((AB)_{23}\) is the dot product of the second row of \(A\) with the third column of \(B\text{.}\) You can access matrix elements using A[i,j] where indices start from 0.

Subsection 2.2.2 \(AB\neq BA\)

For linear algebra, the most inconvenience is non-commutativity, that is, \(AB\neq BA\) in general. Let check it!
Example Let
\begin{equation*} A = \begin{pmatrix} 3 \amp 4 \\ 7 \amp 8 \end{pmatrix}, B = \begin{pmatrix} 5 \amp 3\\ 2 \amp 1 \end{pmatrix}. \end{equation*}
Show that \(AB\neq BA\text{.}\)

Insight 2.2.5.

Why Non-Commutativity is Actually Beautiful: At first glance, the failure of commutativity in matrix multiplication might seem like an unfortunate limitationβ€”after all, we’re used to \(3 \times 5 = 5 \times 3\) with regular numbers. But this "failure" is actually one of the most powerful features of matrices!
Consider this: when you put on your shoes and then tie them, you get a different result than if you tie your shoes first and then try to put them on. Similarly, when you rotate an object and then translate it, the final position differs from translating first and then rotating. Matrix multiplication captures this essential property of real-world transformationsβ€”order matters.
This non-commutativity allows matrices to model:
  • Rotations in 3D space: Rotating around the x-axis then y-axis gives a different orientation than y-axis then x-axis
  • Function composition: Applying function \(f\) then \(g\) is generally different from applying \(g\) then \(f\)
  • Quantum mechanics: The famous uncertainty principle emerges because position and momentum operators don’t commute
  • Computer graphics: The sequence of transformations (scale, rotate, translate) determines the final appearance
So rather than being a limitation, non-commutativity is what makes matrices so expressive and powerful for describing the complex, order-dependent world around us.

Subsection 2.2.3 Matrix Multiplication Examples

Example 2.2.6. Rotation Matrix.

For example, the rotation matrix in a 2-d space can be defined as:
\begin{equation*} \mathbf{A} = \begin{bmatrix} \cos(\theta) & -\sin(\theta)\\ \sin(\theta) & \cos(\theta) \end{bmatrix} \end{equation*}
This matrix rotates a vector about the origin by the angle \(\theta\) (with counterclockwise rotation for a positive \(\theta\)).

Example 2.2.7. Stretching Matrix.

Another example is the stretching matrix B in a 2-d space which is defined as:
\begin{equation*} \mathbf{B} = \begin{bmatrix} k & 0\\ 0 & 1 \end{bmatrix} \end{equation*}
This matrix stretches a vector along the x-axis by a constant factor k but does not affect it in the y-direction.
Similarly, we can have a stretching matrix in y-direction:
\begin{equation*} \mathbf{C} = \begin{bmatrix} 1 & 0\\ 0 & k \end{bmatrix} \end{equation*}