Linear AlgebraLinear Transformations

Composition as Matrix Multiplication

Doing S after T has matrix ST.

Not started Jump to practice

Doing one plane map after another gives a new map. This is where matrix multiplication comes from, and it explains why the order of a product matters.

If $T(\mathbf{x}) = A\mathbf{x}$ and $S(\mathbf{x}) = B\mathbf{x}$, the composition $S \circ T$ means "first $T$, then $S$": $(S \circ T)(\mathbf{x}) = S(T(\mathbf{x}))$.

Key idea

"First $T$ (matrix $A$), then $S$ (matrix $B$)" has standard matrix $BA$. The first map is written on the right, next to $\mathbf{x}$.

Why it works

$S(T(\mathbf{x})) = B(A\mathbf{x}) = (BA)\mathbf{x}$, by the associative law, which is exactly what matrix multiplication was built to satisfy. Read a product right to left, the way the vector travels: in $BA\mathbf{x}$, the vector meets $A$ first.

Worked example: Rotate, then reflect

Find the matrix of "rotate $90^\circ$ counterclockwise, then reflect across the $x$-axis".
  1. Rotation: $A = \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}$. Reflection: $B = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}$.
  2. First $A$, then $B$: $BA$ $= \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}$ $= \begin{bmatrix} 0 & -1 \\ -1 & 0 \end{bmatrix}$.
  3. Check with $\mathbf{e}_1$: rotating gives $(0, 1)$; reflecting that gives $(0, -1)$, which is column 1 of $BA$. ✓
  4. The result is the reflection across $y = -x$.

Answer: $\begin{bmatrix} 0 & -1 \\ -1 & 0 \end{bmatrix}$

Worked example: The other order

Now reflect first, then rotate.
  1. $AB$ $= \begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}$ $= \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}$: the reflection across $y = x$.
  2. A different map, so $AB \neq BA$. The pictures below show both.

Answer: $\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}$

Rotate $90^\circ$, then reflect across the $x$-axis: $BA$. Press "Apply A" (here the product) and watch the F.
Reflect first, then rotate: $AB$. A different reflection.

Worked example: Angle addition from matrices

Show that rotating by $\alpha$ and then by $\beta$ is rotating by $\alpha + \beta$, and see what that says about cosines.
  1. $$R_\beta R_\alpha = \begin{bmatrix} \cos\beta & -\sin\beta \\ \sin\beta & \cos\beta \end{bmatrix}\begin{bmatrix} \cos\alpha & -\sin\alpha \\ \sin\alpha & \cos\alpha \end{bmatrix}$$
  2. The top-left entry is $\cos\beta\cos\alpha - \sin\beta\sin\alpha$, and the bottom-left is $\sin\beta\cos\alpha + \cos\beta\sin\alpha$.
  3. Geometrically the product is $R_{\alpha + \beta}$, whose first column is $(\cos(\alpha + \beta), \sin(\alpha + \beta))$. Matching entries gives the angle addition formulas.

Answer: $\cos(\alpha + \beta) = \cos\alpha\cos\beta - \sin\alpha\sin\beta$

Common mistake

Multiplying in the order the maps are applied, getting $AB$ for "first $A$, then $B$". Check with one vector: apply the maps to $\mathbf{e}_1$ by hand, one at a time, and compare with column 1 of your product.

The same rule works for longer chains and for maps between different spaces. "First $A$, then $B$, then $C$" is $CBA$. If $T: \mathbb{R}^n \to \mathbb{R}^m$ and $S: \mathbb{R}^m \to \mathbb{R}^p$, then $A$ is $m \times n$, $B$ is $p \times m$, and $BA$ is $p \times n$: the sizes match exactly because the output space of $T$ is the input space of $S$. To undo a chain, undo the last step first: $(BA)^{-1} = A^{-1}B^{-1}$.

Rotations about the origin commute with each other ($R_\alpha R_\beta = R_\beta R_\alpha$), but rotations and reflections generally do not.

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 2 XP.

Loading practice…

Builds on

Leads to

Sources and further reading

  • Margalit and Rabinoff, Interactive Linear Algebra (Georgia Tech), §3.4 Matrix Multiplication
  • MIT OpenCourseWare 18.06 Linear Algebra (Gilbert Strang, Spring 2010), Lecture 30: Linear Transformations and Their Matrices
@teddyrookbook GitHub