---
title: Matrices as transformations
heading: A matrix moves every point of the plane at once
eyebrow: A7 · Lesson 4 · Matrices as transformations
xp: 40
---

::: hook
A grid of numbers like $\begin{bmatrix} 2 & 1 \\ 0 & 1 \end{bmatrix}$ looks like bookkeeping. It's really a machine that moves every point of the plane: stretching, shearing, rotating or flattening it. Once you can picture what a matrix does to the plane, questions like "can this system of equations be solved?" become questions about shapes.

::: play
- The two solid arrows are where the matrix sends the basis vectors $(1, 0)$ and $(0, 1)$: its first and second columns. The parallelogram is where the unit square lands, and the curve is where the unit circle lands.
- Set the matrix to $\begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}$ (a shear) and watch the square lean. Then try $\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}$.
- Make the two columns point along the same line. What happens to the square, and to the number in the strip?
:::
:::

```sim plot
view: complex
range: 2.5
slider: a = -2..2 step 0.25 = 1.5
slider: b = -2..2 step 0.25 = 0.5
slider: c = -2..2 step 0.25 = 0
slider: d = -2..2 step 0.25 = 1
curve: (a*cos(u) + b*sin(u)) + j*(c*cos(u) + d*sin(u)) | over: u = 0..2*pi | dashed | color: ch4 | label: circle's image
arrow: a + j*c | label: col 1
arrow: b + j*d | color: ch2 | label: col 2
arrow: b + j*d | from: a + j*c | dashed | color: ch2
arrow: a + j*c | from: b + j*d | dashed
readout: det = a*d - b*c
```

::: predict
## The matrix $\begin{bmatrix} 0 & -1 \\ 1 & 0 \end{bmatrix}$ sends $(1, 0)$ to $(0, 1)$ and $(0, 1)$ to $(-1, 0)$. What does it do to the whole plane?

- [ ] Reflects it in the diagonal
- [x] Rotates it a quarter turn counterclockwise
- [ ] Squashes it onto a line
- [ ] Doubles its size

::: reveal
It rotates the plane a quarter turn counterclockwise. Both basis vectors turn 90° and keep their length, and since every vector is a combination of the two, every vector turns 90°. It's the matrix version of multiplying by $j$ from A3.
:::
:::

::: nameit
## The columns are where the basis goes

Multiplying a matrix by a vector combines the matrix's columns, using the vector's entries as weights:

$$\begin{bmatrix} a & b \\ c & d \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix} = x\begin{bmatrix} a \\ c \end{bmatrix} + y\begin{bmatrix} b \\ d \end{bmatrix} = \begin{bmatrix} ax + by \\ cx + dy \end{bmatrix}$$

So the first column is where $(1, 0)$ lands and the second is where $(0, 1)$ lands. Since every vector is a combination of those two, knowing where they go tells you where everything goes. That's what makes the map **linear**: $A(\mathbf{u} + \mathbf{v}) = A\mathbf{u} + A\mathbf{v}$ and $A(c\mathbf{v}) = cA\mathbf{v}$. Straight lines stay straight, the origin stays put, and the grid stays evenly spaced.

| Matrix | Does |
|---|---|
| $\begin{bmatrix} k & 0 \\ 0 & k \end{bmatrix}$ | scales by $k$ |
| $\begin{bmatrix} 1 & k \\ 0 & 1 \end{bmatrix}$ | shears horizontally |
| $\begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix}$ | rotates by θ |
| $\begin{bmatrix} 1 & 0 \\ 0 & 0 \end{bmatrix}$ | projects onto the horizontal axis |

**Doing one after another** is the **matrix product**. Applying $B$ then $A$ is $AB$: each column of $AB$ is $A$ times the matching column of $B$. Order matters: rotating then shearing differs from shearing then rotating, so in general $AB \ne BA$.

**In circuits**, $G\mathbf{v} = \mathbf{i}$ says the conductance matrix maps node voltages to the currents injected at the nodes. Solving the circuit means running that map backward: which voltages produce the given currents?
:::

::: example
## Where does the shear $\begin{bmatrix}1 & 1\\0 & 1\end{bmatrix}$ send the unit square?

::: solution
1. **Read the columns.** The columns say $(1, 0) \to (1, 0)$ and $(0, 1) \to (1, 1)$.
2. **Map the corners.** The square becomes a parallelogram leaning right, with corners $(0, 0)$, $(1, 0)$, $(2, 1)$ and $(1, 1)$.
3. **Area.** Its area is still 1: a shear slides layers without stretching them.

**Answer:** a parallelogram leaning right, with corners $(0, 0)$, $(1, 0)$, $(2, 1)$ and $(1, 1)$ and area 1.
:::
:::

::: example
## Rotate $(3, 1)$ by 90° counterclockwise.

::: solution
1. **The rotation matrix.**
   $$R = \begin{bmatrix}0 & -1\\1 & 0\end{bmatrix}$$
2. **Multiply.**
   $$\begin{aligned} R\begin{bmatrix}3\\1\end{bmatrix} &= \begin{bmatrix}0 \cdot 3 - 1 \cdot 1\\1 \cdot 3 + 0 \cdot 1\end{bmatrix} \\ &= \begin{bmatrix}-1\\3\end{bmatrix} \end{aligned}$$
3. **Check.** Its length is still $\sqrt{10}$, and its dot product with $(3, 1)$ is zero.

**Answer:** $(3, 1)$ turns to $(-1, 3)$.
:::
:::

::: example
## Which matrix drops every point straight down onto the $x$ axis, and what does it do to the unit square?

::: solution
1. **Choose the columns.** It must send $(1, 0)$ to itself and $(0, 1)$ to $(0, 0)$, so its columns are those two images:
   $$P = \begin{bmatrix}1 & 0\\0 & 0\end{bmatrix}$$
2. **The unit square.** It collapses onto the segment from 0 to 1 on the $x$ axis, with zero area.
3. **No way back.** Every point above or below a spot on that segment lands on the same spot, so there's no way to undo $P$: it's the first example of a matrix with no inverse.

**Answer:** $P = \begin{bmatrix}1 & 0\\0 & 0\end{bmatrix}$. It flattens the unit square onto the segment from 0 to 1 on the $x$ axis, and it has no inverse.
:::
:::

::: check
kind: parts
given: a = 1..5 int; b = -3 | -1 | 1 | 3; c = -2 | 2; d = 1..5 int; x = 1..3 int; y = 1..3 int

## Compute $\begin{bmatrix} \given{a} & \given{b} \\ \given{c} & \given{d} \end{bmatrix}\begin{bmatrix} \given{x} \\ \given{y} \end{bmatrix}$.

::: part
answer: a*x + b*y
tolerance: 0.001

### First component?

::: misses
- [a*x + c*y] Use the first row: $a$ and $b$.
- [any] The first row times the vector: $ax + by$.
:::
:::

::: part
answer: c*x + d*y
tolerance: 0.001

### Second component?

::: misses
- [b*x + d*y] Use the second row: $c$ and $d$.
- [any] The second row times the vector: $cx + dy$.
:::
:::

::: right
Right. Equivalently: {x} times the first column plus {y} times the second.
:::
:::

::: check
given: t = 30 | 45 | 60 | 120
answer: -sin(t°)
tolerance: 0.5%

## What is the top-right entry of the matrix that rotates the plane by {t}° counterclockwise?

::: right
Right. The second column is where $(0, 1)$ lands: $(-\sin\theta, \cos\theta)$, so the top-right entry is $-\sin\given{t}°$.
:::

::: misses
- [sin(t°)] That's the bottom-left entry. Where does $(0, 1)$ go when it turns {t}°? To the left, so its x is negative.
- [cos(t°)] That's a diagonal entry.
- [any] Not yet. The second column is the image of $(0, 1)$ after turning {t}°.
:::
:::

::: check
given: p = 1..3 int; q = 2..3 int; r = 1..3 int; s = 1..3 int
answer: p*r + q*s
tolerance: 0.001

## For $A = \begin{bmatrix} \given{p} & \given{q} \\ 0 & 1 \end{bmatrix}$ and $B = \begin{bmatrix} \given{r} & 0 \\ \given{s} & 1 \end{bmatrix}$, what is the top-left entry of $AB$?

::: right
Right. Row 1 of $A$ dotted with column 1 of $B$: $\given{p}\cdot\given{r} + \given{q}\cdot\given{s}$.
:::

::: misses
- [p*r] Include the second product: row 1 of A with all of column 1 of B.
- [p*r + s] Multiply the {q} by the {s}.
- [any] Entry (1, 1) of $AB$ is row 1 of $A$ dotted with column 1 of $B$.
:::
:::

::: check
kind: choice

## A matrix sends the unit square to a parallelogram of zero area: a line segment. What does that tell you?

- [x] Its columns point along the same line, so it squashes the plane onto a line and can't be undone
- [ ] It's a rotation
- [ ] It's the identity
- [ ] Nothing, as long as its entries aren't zero

::: right
Right. Different points land on the same spot, so no inverse exists. Lesson 30 measures this with the determinant.
:::

::: misses
- [2] Rotations keep areas the same.
- [3] The identity leaves the square as it is.
- [4] A matrix with all nonzero entries can still have dependent columns, like $\begin{bmatrix} 1 & 2 \\ 2 & 4 \end{bmatrix}$.
:::
:::

::: check
kind: parts
given: a = 2 | 3; b = 1 | 4

## Consider $A = \begin{bmatrix}\given{a} & 1\\0 & \given{b}\end{bmatrix}$.

::: part
answer: a + 1
tolerance: 0.5%

### Where does $(1, 1)$ go? Give its $x$ coordinate.

::: misses
- [any] Add the two columns.
:::
:::

::: part
answer: a*b
tolerance: 0.5%

### What is the area of the image of the unit square?

::: misses
- [a + b] The area factor multiplies.
- [any] The image is a parallelogram with sides along the two columns.
:::
:::
:::

::: check
kind: derivation
vars: t = 0.1..1.5

## Build the matrix that rotates by $t$ radians.

::: step
answer: cos(t)

### Where does $(1, 0)$ go? Give its $x$ coordinate.
:::

::: step
answer: -sin(t)

### Where does $(0, 1)$ go? Give its $x$ coordinate.
:::

::: step
answer: cos(t) - sin(t)

### Add the columns: what is the $x$ coordinate of the image of $(1, 1)$?
:::

::: right
Right. The columns are the images of the basis vectors, and every other point follows by combination.
:::
:::

::: explain
## Why is knowing where a matrix sends $(1, 0)$ and $(0, 1)$ enough to know where it sends every vector?

::: model
Every vector $(x, y)$ is $x$ times $(1, 0)$ plus $y$ times $(0, 1)$. A matrix is linear: it sends a sum to the sum of the images and a multiple to the same multiple of the image. So $(x, y)$ goes to $x$ times the image of $(1, 0)$ plus $y$ times the image of $(0, 1)$, and those two images are the matrix's columns.
:::
:::

::: practice

::: check
given: a = -5 | -3 | -1 | 1 | 3 | 5; b = -4 | -2 | 2 | 4; c = -5..5 int; d = -5..5 int
answer: a
tolerance: 0.001

## Where does $\begin{bmatrix} \given{a} & \given{b} \\ \given{c} & \given{d} \end{bmatrix}$ send $(1, 0)$? Give the first component.

::: misses
- [b] $(1, 0)$ picks out the first column.
- [any] The image of $(1, 0)$ is the first column.
:::
:::

::: check
given: k = 2..5 int; x = 1..9 int; y = 1..9 int
answer: x + k*y
tolerance: 0.001

## The shear $\begin{bmatrix} 1 & \given{k} \\ 0 & 1 \end{bmatrix}$ acts on $(\given{x}, \given{y})$. What is the new first component?

::: misses
- [x] The shear adds {k} times the second component.
- [any] $x + ky$.
:::
:::

::: check
given: a = 1 | 3; b = 1..4 int; c = 2 | 4; d = 2 | 4
answer: c*a + d*c
tolerance: 0.001

## For $A = \begin{bmatrix} \given{a} & \given{b} \\ \given{c} & \given{d} \end{bmatrix}$, what is the bottom-left entry of $A^2 = AA$?

::: misses
- [c^2] Row 2 of A dotted with column 1 of A: $c \cdot a + d \cdot c$.
- [any] Row 2 times column 1.
:::
:::
:::
