Monocurl Essays
Series Download

Solving Ax = b by undoing a transformation

A linear system asks which vector a matrix sends to b. That view explains when there is one solution, none or a whole line, and what the inverse matrix does.

19 min·Early college·

AssumesA matrix is a transformation of spaceThe determinant is how much area gets scaledSolving two equations at once: where lines meet

The film of the transformation $A$, with columns $(3, 1)$ and $(1, 2)$, run backwards. It starts with the plane already transformed and the black dot sitting on the target $\mathbf{b} = (5, 3)$, the green ring. As the grid relaxes to the ordinary one, the dot is carried back to where it came from, $(1.4, 0.8)$.
Monocurl source
let Film = |t| {
    let m = blend(IDENT, A7, t)
    let p = apply(m, SOL)
    return [
        Lines(Bd, m),
        Arrows(Bd, m),
        Pt(P(Bd, p), INK, 0.11),
        MatBox([RX, 1.0, 0], m, 1),
        center{[RX - 0.45, -1.15, 0]} scale{1.15} color{INK} Number(clean(p[0]), 2),
        center{[RX + 0.45, -1.15, 0]} scale{1.15} color{INK} Number(clean(p[1]), 2)
    ]
}
mesh ground = Ground(Bd)
mesh target = Ring(P(Bd, BT), LEAF, 0.17, 4)
mesh film = Film(t: 1)
mesh label = [center{[RX, -0.6, 0]} Note("the dot is at", 0.76)]

slide "rewind"
    play Wait(1.2)
    film.t = 0
    play Lerp(4.5, [&film])
    play Wait(2)

Uses the shared definitions for this lesson's figures.

Here is a pair of equations of the kind you have solved many times:

$$ 3x + y = 5, \qquad x + 2y = 3. $$

Elimination gives $x = 1.4$, $y = 0.8$, and that would be the end of it, except for a nagging fact about such systems. Most of them have exactly one solution, and now and then one turns up with no solution or with infinitely many. The method does not warn you. It just breaks down partway, with an equation like $0 = 4$ or $0 = 0$. What decides which kind of system you are holding?

The answer comes from reading the same two equations as one statement about a transformation. Collect the coefficients into a matrix and the unknowns and right-hand sides into vectors:

$$ A = \begin{pmatrix} 3 & 1 \\ 1 & 2 \end{pmatrix}, \qquad \mathbf{x} = \begin{pmatrix} x \\ y \end{pmatrix}, \qquad \mathbf{b} = \begin{pmatrix} 5 \\ 3 \end{pmatrix}. $$

A matrix is a transformation of the plane: $A$ sends $(x, y)$ to $(3x + y,\ x + 2y)$, which is $x$ times its first column $(3, 1)$ plus $y$ times its second column $(1, 2)$. So the system says $A\mathbf{x} = \mathbf{b}$, and it asks: which vector does $A$ send to $\mathbf{b}$? In the animation the plane has already been transformed and a dot sits on $\mathbf{b}$. Running the film backwards carries the dot to its starting point, and that starting point is the solution.

Seen this way, the three kinds of system correspond to three things that can happen at the target: one point lands on $\mathbf{b}$, no point does, or many do. I will use two facts about the determinant: $\det\begin{pmatrix} a & b \\ c & d \end{pmatrix} = ad - bc$ is zero exactly when the columns are parallel, and when it is not zero the matrix has an inverse $A^{-1} = \frac{1}{ad - bc}\begin{pmatrix} d & -b \\ -c & a \end{pmatrix}$ with $A^{-1}A = AA^{-1} = I$.

Three readings of one system

It is worth setting the readings side by side, because each makes something different easy to see.

In the row picture, familiar from school algebra, each equation is a line and the solution is the point where the lines cross. The left side of each equation is the dot product of a row of $A$ with $\mathbf{x}$, so each line is perpendicular to its row: the blue line below is perpendicular to $(3, 1)$.

The row picture of the system. The blue line is 3x + y = 5, the orange line is x + 2y = 3, and they cross at the solution (1.4, 0.8).
The row picture of the system. The blue line is $3x + y = 5$, the orange line is $x + 2y = 3$, and they cross at the solution $(1.4, 0.8)$.
Monocurl source
mesh ground = Ground(Bd)
mesh rows = [
    RowLine(Bd, [3, 1, 5], SOL, AZURE),
    RowLine(Bd, [1, 2, 3], SOL, EMBER)
]
mesh point = Ring(P(Bd, SOL), LEAF, 0.13, 4)
mesh legend = [
    center{[RX, 1.0, 0]} Math("3x + y = 5", 0.95, AZURE),
    center{[RX, 0.3, 0]} Math("x + 2y = 3", 0.95, EMBER),
    center{[RX, -0.6, 0]} Math(str_join(["(", to_string(SOL[0], 1), ",\ ", to_string(SOL[1], 1), ")"]), 0.95, LEAF)
]

Uses the shared definitions for this lesson's figures.

In the column picture, the unknowns are amounts. The system reads

$$ x\begin{pmatrix} 3 \\ 1 \end{pmatrix} + y\begin{pmatrix} 1 \\ 2 \end{pmatrix} = \begin{pmatrix} 5 \\ 3 \end{pmatrix}, $$

and asks how much of each column to mix in order to reach $\mathbf{b}$.

  1. The two columns of A, and the target b = (5, 3) in green. How much of each column is needed to reach it?
  2. Take 1.4 of the blue column. That reaches (4.2, 1.4).
  3. Add 0.8 of the orange column. The path ends exactly on b.
The column picture of the same system: $1.4$ of the first column $(3, 1)$ followed by $0.8$ of the second column $(1, 2)$ arrives exactly at $\mathbf{b} = (5, 3)$.
Monocurl source
let c1 = [A7[0], A7[2]]
let c2 = [A7[1], A7[3]]
let mid = times(SOL[0], c1)
let Line2 = |y, tex, col| center{[RX, y, 0]} Math(tex, 0.92, col)
mesh ground = Ground(Bd)
mesh target = Ring(P(Bd, BT), LEAF, 0.17, 4)
mesh mix = []
mesh cols = Arrows(Bd, A7)
mesh tally = [Line2(1.1, "x\,(3, 1) + y\,(1, 2)", INK), Line2(0.5, "= (5, 3)", LEAF)]

slide "The two columns of A, and the target b = (5, 3) in green. How much of each column is needed to reach it?"
    play Fade(0.5)

slide "Take 1.4 of the blue column. That reaches (4.2, 1.4)."
    mix = [Vec(Bd, [0, 0], mid, tint(AZURE, 0.55), 9, 0.26)]
    tally .= Line2(-0.4, str_join(["x = ", to_string(SOL[0], 1)]), AZURE)
    play Fade(0.6, [&mix, &tally])

slide "Add 0.8 of the orange column. The path ends exactly on b."
    mix .= Vec(Bd, mid, add(mid, times(SOL[1], c2)), tint(EMBER, 0.6), 9, 0.26)
    tally .= Line2(-1.0, str_join(["y = ", to_string(SOL[1], 1)]), EMBER)
    play Fade(0.6, [&mix, &tally])

Uses the shared definitions for this lesson's figures.

The transformation picture is the column picture for all vectors at once: $A$ moves every point of the plane, and we want the point that ends up at $\mathbf{b}$.

Pause and try

Using only the column picture, find $\mathbf{x}$ with $A\mathbf{x} = \mathbf{b}$ for (a) $\mathbf{b} = (3, 1)$, (b) $\mathbf{b} = (4, 3)$, (c) $\mathbf{b} = (5, 0)$. (For the last one, think about which column needs to be cancelled.)

Show answerHide answer

(a) $(3, 1)$ is the first column itself: $\mathbf{x} = (1, 0)$. (b) $(4, 3) = (3, 1) + (1, 2)$, one of each: $\mathbf{x} = (1, 1)$. (c) We need $y$ to cancel the height: $x + 2y = 0$ means $x = -2y$, and then $3x + y = -5y = 5$ gives $y = -1$, $x = 2$. Check: $2\,(3, 1) - (1, 2) = (5, 0)$.

When the film can be run backwards

If $A$ has an inverse, the matrix $A^{-1}$ is the film run backwards: it sends every output of $A$ to the input it came from. Then the system is solved by applying $A^{-1}$ to the target.

The two halves of the proof use the two halves of the definition of an inverse. $AA^{-1} = I$ gives existence, and $A^{-1}A = I$ gives uniqueness.

The letter F is carried away by $A$ and then brought back by $A^{-1}$. The matrix shown is the combined transformation so far: it runs from the identity to $A$, and then, as $A^{-1}$ is applied on top, back to the identity.
Monocurl source
let Round = |s| {
    let m = matmul(blend(IDENT, A7INV, clamp(0, s - 1, 1)), blend(IDENT, A7, clamp(0, s, 1)))
    return [
        Lines(Bd, m),
        Shape(map(FPTS, |p| P(Bd, apply(m, times(0.5, p)))), LEAF, 0.3, 2.5),
        Arrows(Bd, m),
        MatBox([RX, 0.9, 0], m, 1)
    ]
}
mesh ground = Ground(Bd)
mesh round = Round(s: 0)
mesh note = []

slide "there and back"
    play Wait(0.8)
    round.s = 1
    play Lerp(2.6, [&round])
    note = [center{[RX, -0.4, 0]} Math("\text{apply } A", 0.95, INK)]
    play Fade(0.4, [&note])
    play Wait(0.8)
    round.s = 2
    play Lerp(2.6, [&round])
    note .= center{[RX, -1.05, 0]} Math("\text{then } A^{-1}", 0.95, LEAF)
    play Fade(0.4, [&note])
    play Wait(1.8)

Uses the shared definitions for this lesson's figures.

When the plane is squashed

Now take a matrix whose determinant is zero:

$$ Z = \begin{pmatrix} 2 & 4 \\ 1 & 2 \end{pmatrix}, \qquad \det Z = 2 \cdot 2 - 4 \cdot 1 = 0. $$

Its columns $(2, 1)$ and $(4, 2)$ are parallel, so every output $x\,(2, 1) + y\,(4, 2) = (x + 2y)\,(2, 1)$ lies on the line through the origin along $(2, 1)$. The whole plane is squashed onto that line. Two consequences are visible before any algebra. A target off the line is never hit. And a target on the line is hit by many points at once, because a plane’s worth of inputs has been packed into a line’s worth of outputs.

Pause and try

Find all solutions of $Z\mathbf{x} = (4, 2)$, and all solutions of $Z\mathbf{x} = (0, 0)$. How are the two sets related? Then try $Z\mathbf{x} = (4, 3)$.

Show answerHide answer

$Z(x, y) = (2x + 4y,\ x + 2y)$. For the target $(4, 2)$ both equations say $x + 2y = 2$, so the solutions form a line: $(2, 0)$, $(0, 1)$, $(4, -1)$ and so on. For the target $(0, 0)$ both say $x + 2y = 0$: the parallel line through the origin, containing $(0, 0)$, $(2, -1)$, $(-2, 1)$. The first line is the second one shifted by $(2, 0)$. For $(4, 3)$ the equations say $x + 2y = 2$ and $x + 2y = 3$, which cannot both hold: no solutions.

  1. Before the transformation: the green points lie on the line x + 2y = 2, the purple points on the parallel line through the origin.
  2. Apply Z. The plane is squashed onto the line along (2, 1). Every green point lands on (4, 2) and every purple point on (0, 0).
  3. The target (4, 3), in red, is off that line. No point of the plane lands there.
  4. Run the film backwards. The single point (4, 2) spreads out into the whole green line of solutions.
The matrix $Z$ with columns $(2, 1)$ and $(4, 2)$ squashes the plane onto a line. The green points, on the line $x + 2y = 2$, all land on $(4, 2)$; the purple points, on the parallel line through the origin, all land on $(0, 0)$; and nothing lands on $(4, 3)$.
Monocurl source
let GREEN = [[-2, 2], [0, 1], [2, 0], [4, -1]]
let PURP = [[-2, 1], [0, 0], [2, -1], [4, -2]]
let Sq = |t| {
    let m = blend(IDENT, Z7, t)
    return [
        Lines(B2, m),
        map(PURP, |p| Pt(P(B2, apply(m, p)), PLUM, 0.1)),
        map(GREEN, |p| Pt(P(B2, apply(m, p)), LEAF, 0.1))
    ]
}
let Line2 = |y, tex, col| center{[RX + 0.05, y, 0]} Math(tex, 0.9, col)
mesh ground = Ground(B2)
mesh memory = [
    Cut(B2, [-4, 3], [6, -2], tint(LEAF, 0.45), 3),
    Cut(B2, [-4, 2], [6, -3], tint(PLUM, 0.45), 3)
]
mesh rings = []
mesh sq = Sq(t: 0)
mesh tally = [Line2(1.2, "x + 2y = 2", LEAF), Line2(0.5, "x + 2y = 0", PLUM)]

slide "Before the transformation: the green points lie on the line x + 2y = 2, the purple points on the parallel line through the origin."
    play Fade(0.5)

slide "Apply Z. The plane is squashed onto the line along (2, 1). Every green point lands on (4, 2) and every purple point on (0, 0)."
    tally = []
    play Fade(0.3, [&tally])
    sq.t = 1
    play Lerp(3, [&sq])
    tally = [Line2(1.2, "Z\mathbf{x} = (4, 2)", LEAF), center{[RX + 0.05, 0.7, 0]} Note("a whole line of x", 0.74)]
    play Fade(0.4, [&tally])

slide "The target (4, 3), in red, is off that line. No point of the plane lands there."
    rings = [Ring(P(B2, [4, 3]), ROSE, 0.15, 4)]
    tally .= Line2(-0.1, "Z\mathbf{x} = (4, 3)", ROSE)
    tally .= center{[RX + 0.05, -0.6, 0]} Note("no solution", 0.74)
    play Fade(0.4, [&rings, &tally])

slide "Run the film backwards. The single point (4, 2) spreads out into the whole green line of solutions."
    sq.t = 0
    play Lerp(3, [&sq])

Uses the shared definitions for this lesson's figures.

The line of inputs that $Z$ sends to the origin deserves a name, because it controls everything else.

The kernel always contains $\mathbf{0}$. For an invertible matrix it contains nothing else, by the uniqueness theorem with $\mathbf{b} = \mathbf{0}$. For $Z$ the kernel is the line $x + 2y = 0$, and the image is the line along $(2, 1)$. We have met kernels before under another name: the eigenvectors of a matrix $A$ for an eigenvalue $\lambda$ are the nonzero vectors in the kernel of $A - \lambda I$.

Part 3 used nothing but linearity, so it holds for matrices of any size: the solutions of $A\mathbf{x} = \mathbf{b}$, if there are any, are one particular solution plus the kernel. The zero matrix, left out of the theorem, sends everything to $\mathbf{0}$: its kernel is the whole plane, and $A\mathbf{x} = \mathbf{b}$ is solved by every $\mathbf{x}$ if $\mathbf{b} = \mathbf{0}$ and by none otherwise.

The solutions of Z\mathbf{x} = (4, 2) form the green line. Each is the particular solution \mathbf{x}_p = (2, 0) (black arrow) plus a vector from the kernel, the purple line through the origin: for example (2, 0) + (-2, 1) = (0, 1).
The solutions of $Z\mathbf{x} = (4, 2)$ form the green line. Each is the particular solution $\mathbf{x}_p = (2, 0)$ (black arrow) plus a vector from the kernel, the purple line through the origin: for example $(2, 0) + (-2, 1) = (0, 1)$.
Monocurl source
mesh ground = Ground(B2)
mesh lines = [
    Cut(B2, [-4, 2], [6, -3], PLUM, 3),
    Cut(B2, [-4, 3], [6, -2], LEAF, 3)
]
mesh arrows = [
    Vec(B2, [0, 0], [-2, 1], PLUM),
    Vec(B2, [2, 0], [0, 1], PLUM),
    Vec(B2, [0, 0], [2, 0], INK)
]
mesh dots = map([[-2, 2], [0, 1], [2, 0], [4, -1]], |p| Pt(P(B2, p), LEAF, 0.1))
mesh legend = [
    center{[RX + 0.05, 1.2, 0]} Math("Z\mathbf{x} = (4, 2)", 0.92, LEAF),
    center{[RX + 0.05, 0.4, 0]} Math("Z\mathbf{n} = (0, 0)", 0.92, PLUM),
    center{[RX + 0.05, -0.5, 0]} Math("\mathbf{x} = \mathbf{x}_p + \mathbf{n}", 0.92, INK)
]

Uses the shared definitions for this lesson's figures.

So the determinant of the coefficient matrix is the number that decides what kind of system you are holding, and it does so without looking at the right-hand side. The right-hand side only matters in the squashed case, where it decides between “none” and “a line”.

Row reduction, the practical method

Knowing that a solution exists is different from finding it. For two unknowns the inverse formula is quick, but for larger systems the method everyone uses, by hand and by computer, is the organized form of elimination called row reduction or Gaussian elimination. We keep only the numbers, in an array with the right-hand side after a bar (the augmented matrix), and allow three operations on its rows:

  1. swap two rows;
  2. multiply a row by a nonzero number;
  3. add a multiple of one row to another row.

None of these changes the set of solutions. A vector that satisfies both old equations satisfies both new ones, since the new ones are combinations of the old. And each operation can be undone by an operation of the same kind (swap back, multiply by the reciprocal, subtract the same multiple), so by the same argument a vector that satisfies the new equations satisfies the old ones.

The aim is to reach rows that say $x = \dots$ and $y = \dots$ outright. Watch what the operations do to the two lines of the row picture.

  1. Each row of the array is an equation, and each equation is a line. The solution is the crossing point.
  2. Swap the rows so that the one starting with 1 is on top. The two lines are the same; only their order changed.
  3. Subtract 3 times row 1 from row 2. The new row 2 has no x in it, so its line is horizontal.
  4. Divide row 2 by -5. Its line does not move, and the row now reads y = 0.8.
  5. Subtract 2 times row 2 from row 1. Its line swings to vertical, and the row reads x = 1.4.
Row reduction of the system $3x + y = 5$, $x + 2y = 3$. Each row is a line, row 1 in blue and row 2 in orange. The operations turn the lines about their crossing point until one is vertical and one is horizontal, and the array then reads $x = 1.4$, $y = 0.8$.
Monocurl source
let Rows = |r1, r2| [
    RowLine(Bd, r2, SOL, EMBER),
    RowLine(Bd, r1, SOL, AZURE),
    Ring(P(Bd, SOL), LEAF, 0.12, 4)
]
let Op = |tex| center{[RX - 0.08, -0.55, 0]} Math(tex, 0.95, SLATE)
mesh ground = Ground(Bd)
mesh rows = Rows(r1: [3, 1, 5], r2: [1, 2, 3])
mesh aug = Aug([RX - 0.08, 0.7, 0], [3, 1, 5], [1, 2, 3])
mesh op = []

slide "Each row of the array is an equation, and each equation is a line. The solution is the crossing point."
    play Fade(0.5)

slide "Swap the rows so that the one starting with 1 is on top. The two lines are the same; only their order changed."
    aug = []
    play Fade(0.3, [&aug])
    rows.r1 = [1, 2, 3]
    rows.r2 = [3, 1, 5]
    aug = Aug([RX - 0.08, 0.7, 0], [1, 2, 3], [3, 1, 5])
    op = [Op("R_1 \leftrightarrow R_2")]
    play Fade(0.5, [&rows, &aug, &op])

slide "Subtract 3 times row 1 from row 2. The new row 2 has no x in it, so its line is horizontal."
    aug = []
    op = []
    play Fade(0.3, [&aug, &op])
    rows.r2 = [0, -5, -4]
    play Lerp(2, [&rows])
    aug = Aug([RX - 0.08, 0.7, 0], [1, 2, 3], [0, -5, -4])
    op = [Op("R_2 - 3R_1")]
    play Fade(0.4, [&aug, &op])

slide "Divide row 2 by -5. Its line does not move, and the row now reads y = 0.8."
    aug = []
    op = []
    play Fade(0.3, [&aug, &op])
    aug = Aug([RX - 0.08, 0.7, 0], [1, 2, 3], [0, 1, 0.8])
    op = [Op("R_2 \div (-5)")]
    play Fade(0.4, [&aug, &op])

slide "Subtract 2 times row 2 from row 1. Its line swings to vertical, and the row reads x = 1.4."
    aug = []
    op = []
    play Fade(0.3, [&aug, &op])
    rows.r1 = [1, 0, 1.4]
    play Lerp(2, [&rows])
    aug = Aug([RX - 0.08, 0.7, 0], [1, 0, 1.4], [0, 1, 0.8])
    op = [Op("R_1 - 2R_2")]
    play Fade(0.4, [&aug, &op])

Uses the shared definitions for this lesson's figures.

Written out as arrays, the whole computation is

$$ \left[\begin{array}{cc|c} 3 & 1 & 5 \\ 1 & 2 & 3 \end{array}\right] \to \left[\begin{array}{cc|c} 1 & 2 & 3 \\ 3 & 1 & 5 \end{array}\right] \to \left[\begin{array}{cc|c} 1 & 2 & 3 \\ 0 & -5 & -4 \end{array}\right] \to \left[\begin{array}{cc|c} 1 & 2 & 3 \\ 0 & 1 & 0.8 \end{array}\right] \to \left[\begin{array}{cc|c} 1 & 0 & 1.4 \\ 0 & 1 & 0.8 \end{array}\right]. $$

The left block has become the identity matrix, and the column after the bar is the solution. Because the solution set never changed, every line in the figure passes through the same crossing point at every stage.

Row reduction also detects the squashed case by itself. Try it on $Z\mathbf{x} = (4, 3)$:

$$ \left[\begin{array}{cc|c} 2 & 4 & 4 \\ 1 & 2 & 3 \end{array}\right] \to \left[\begin{array}{cc|c} 1 & 2 & 2 \\ 1 & 2 & 3 \end{array}\right] \to \left[\begin{array}{cc|c} 1 & 2 & 2 \\ 0 & 0 & 1 \end{array}\right]. $$

The last row says $0x + 0y = 1$, which nothing satisfies. With the target $(4, 2)$ the last row would be $0\ 0\ |\ 0$, which says nothing, and the surviving row $x + 2y = 2$ describes the line of solutions. A row of zeros on the left of the bar is how $\det = 0$ shows up during elimination.

The inverse matrix by row reduction

The inverse can be found by the same process. Its first column is $A^{-1}(1, 0)$, the vector that $A$ sends to $(1, 0)$, and its second column is the vector that $A$ sends to $(0, 1)$. So the columns of $A^{-1}$ are the solutions of two systems with the same left side, and we can reduce both at once by putting both right-hand sides after the bar.

Once $A^{-1}$ is known, every system with this coefficient matrix is solved by one multiplication, and the answer depends linearly on the target: doubling $\mathbf{b}$ doubles $\mathbf{x}$, and the solution for a sum of targets is the sum of the solutions.

Pause and try

Use $A^{-1}$ from the example to solve $3x + y = 10$, $x + 2y = 5$. Then, without further calculation, write down the solution of $3x + y = 15$, $x + 2y = 8$, using the fact that $(15, 8) = (10, 5) + (5, 3)$.

Show answerHide answer

$\mathbf{x} = A^{-1}(10, 5) = (4 - 1,\ -2 + 3) = (3, 1)$. Check: $9 + 1 = 10$ and $3 + 2 = 5$. For the second system, the solution is the sum of the solutions for $(10, 5)$ and for $(5, 3)$: $(3, 1) + (1.4, 0.8) = (4.4, 1.8)$. Check: $13.2 + 1.8 = 15$ and $4.4 + 3.6 = 8$.

Two mistakes to avoid

What was hard here was that “solve the system” sounds like a single task, while it hides two different questions: does anything land on $\mathbf{b}$, and how many things do? The transformation picture separates them. The image answers the first question and the kernel answers the second, and for a square matrix the determinant settles both at once. The reusable idea is the shape of the answer, one particular solution plus the kernel, which describes the solutions of every linear equation you will meet, including differential equations.

Check yourself

A $2 \times 2$ system $A\mathbf{x} = \mathbf{b}$ is known to have the two solutions $(1, 2)$ and $(3, 3)$. Which statement must be true?

Problems

The first three are computations, the next three combine the theorems, and the last two ask for arguments.

Problem 1

Solve $2x + y = 7$, $x + 3y = 11$ by row reduction. Then state the solution as a sentence about the columns of the coefficient matrix.

Show solutionHide solution

$\left[\begin{array}{cc|c} 2 & 1 & 7 \\ 1 & 3 & 11 \end{array}\right] \to \left[\begin{array}{cc|c} 1 & 3 & 11 \\ 2 & 1 & 7 \end{array}\right] \to \left[\begin{array}{cc|c} 1 & 3 & 11 \\ 0 & -5 & -15 \end{array}\right] \to \left[\begin{array}{cc|c} 1 & 3 & 11 \\ 0 & 1 & 3 \end{array}\right] \to \left[\begin{array}{cc|c} 1 & 0 & 2 \\ 0 & 1 & 3 \end{array}\right]$, using a swap, $R_2 - 2R_1$, $R_2 \div (-5)$ and $R_1 - 3R_2$. So $x = 2$, $y = 3$. Check: $4 + 3 = 7$ and $2 + 9 = 11$. Column sentence: twice the column $(2, 1)$ plus three times the column $(1, 3)$ equals $(7, 11)$.

Problem 2

Let $M = \begin{pmatrix} 4 & 3 \\ 1 & 1 \end{pmatrix}$. Find $M^{-1}$ and use it to solve $M\mathbf{x} = (10, 3)$ and $M\mathbf{x} = (1, 0)$.

Show solutionHide solution

$\det M = 4 - 3 = 1$, so $M^{-1} = \begin{pmatrix} 1 & -3 \\ -1 & 4 \end{pmatrix}$. Then $M^{-1}(10, 3) = (10 - 9,\ -10 + 12) = (1, 2)$; check: $4 + 6 = 10$, $1 + 2 = 3$. And $M^{-1}(1, 0) = (1, -1)$, the first column of $M^{-1}$; check: $4 - 3 = 1$, $1 - 1 = 0$.

Problem 3

Let $W = \begin{pmatrix} 1 & -2 \\ -3 & 6 \end{pmatrix}$. (a) Find its kernel and its image. (b) Solve $W\mathbf{x} = (2, -6)$. (c) Solve $W\mathbf{x} = (1, 1)$.

Show solutionHide solution

$\det W = 6 - 6 = 0$. (a) Kernel: $x - 2y = 0$ (the second row, $-3x + 6y = 0$, says the same), so the kernel is the line of multiples of $(2, 1)$. Image: the columns $(1, -3)$ and $(-2, 6) = -2\,(1, -3)$ are parallel, so the image is the line of multiples of $(1, -3)$. (b) $(2, -6) = 2\,(1, -3)$ is in the image. One solution is $\mathbf{x}_p = (2, 0)$, since $W(2, 0) = (2, -6)$. All solutions: $(2, 0) + t\,(2, 1)$ for any number $t$, which is the line $x - 2y = 2$. (c) $(1, 1)$ is not a multiple of $(1, -3)$, so there is no solution. By row reduction: adding 3 times row 1 to row 2 in $\left[\begin{array}{cc|c} 1 & -2 & 1 \\ -3 & 6 & 1 \end{array}\right]$ gives the row $0\ 0\ |\ 4$.

Problem 4

Consider the system $x + 2y = 3$, $2x + ky = c$. (a) For which $k$ is there a unique solution whatever $c$ is? (b) For the remaining value of $k$, for which $c$ are there solutions, and what are they?

Show solutionHide solution

The coefficient matrix $\begin{pmatrix} 1 & 2 \\ 2 & k \end{pmatrix}$ has determinant $k - 4$. (a) For $k \neq 4$ the determinant is not zero and the solution is unique for every $c$. (b) For $k = 4$ the second equation is $2x + 4y = c$, while twice the first is $2x + 4y = 6$. If $c = 6$ the two equations agree and the solutions are the line $x + 2y = 3$: $(3, 0) + t\,(-2, 1)$. If $c \neq 6$ they contradict each other and there is no solution. In the language of the lesson: the image is the line along $(1, 2)$, and $(3, c)$ lies on it only when $c = 6$.

Problem 5

Find the inverse of $\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}$ by row reduction, and check it against the formula.

Show solutionHide solution

$\left[\begin{array}{cc|cc} 1 & 2 & 1 & 0 \\ 3 & 4 & 0 & 1 \end{array}\right] \to \left[\begin{array}{cc|cc} 1 & 2 & 1 & 0 \\ 0 & -2 & -3 & 1 \end{array}\right] \to \left[\begin{array}{cc|cc} 1 & 2 & 1 & 0 \\ 0 & 1 & 1.5 & -0.5 \end{array}\right] \to \left[\begin{array}{cc|cc} 1 & 0 & -2 & 1 \\ 0 & 1 & 1.5 & -0.5 \end{array}\right]$, using $R_2 - 3R_1$, $R_2 \div (-2)$, $R_1 - 2R_2$. So the inverse is $\begin{pmatrix} -2 & 1 \\ 1.5 & -0.5 \end{pmatrix}$. Formula: the determinant is $4 - 6 = -2$, and $\frac{1}{-2}\begin{pmatrix} 4 & -2 \\ -3 & 1 \end{pmatrix}$ is the same matrix.

Problem 6

You are told that $A\,(0.4, -0.2) = (1, 0)$ and $A\,(-0.2, 0.6) = (0, 1)$ for a certain matrix $A$, and nothing else about it. Solve $A\mathbf{x} = (5, 3)$, and explain which property of matrices you used.

Show solutionHide solution

Since $(5, 3) = 5\,(1, 0) + 3\,(0, 1)$, try $\mathbf{x} = 5\,(0.4, -0.2) + 3\,(-0.2, 0.6) = (2 - 0.6,\ -1 + 1.8) = (1.4, 0.8)$. By linearity, $A\mathbf{x} = 5\,A(0.4, -0.2) + 3\,A(-0.2, 0.6) = 5\,(1, 0) + 3\,(0, 1) = (5, 3)$. It is the only solution. The two given facts say $AX = I$ for the matrix $X$ with columns $(0.4, -0.2)$ and $(-0.2, 0.6)$, so $\det A \cdot \det X = 1$ by the product rule for determinants, $\det A \neq 0$, and the uniqueness theorem applies. This is why the two given vectors are the columns of $A^{-1}$: the solution for any target is the corresponding mix of the solutions for $(1, 0)$ and $(0, 1)$.

Problem 7

Prove: if a $2 \times 2$ system $A\mathbf{x} = \mathbf{b}$ has two different solutions, then it has infinitely many, and $\det A = 0$.

Show solutionHide solution

Let $\mathbf{x}_1 \neq \mathbf{x}_2$ be solutions and put $\mathbf{n} = \mathbf{x}_1 - \mathbf{x}_2 \neq \mathbf{0}$. Then $A\mathbf{n} = A\mathbf{x}_1 - A\mathbf{x}_2 = \mathbf{b} - \mathbf{b} = \mathbf{0}$. For every number $t$, $A(\mathbf{x}_1 + t\mathbf{n}) = \mathbf{b} + t\,\mathbf{0} = \mathbf{b}$, and these vectors are all different because $\mathbf{n} \neq \mathbf{0}$: infinitely many solutions. If $\det A$ were not zero, the uniqueness theorem would allow only one solution. So $\det A = 0$.

Problem 8

(Cramer’s rule.) Let $A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}$ with $\det A \neq 0$, and let the target be $(e, f)$. Prove that the solution of $A\mathbf{x} = (e, f)$ is

$$ x = \frac{ed - bf}{ad - bc}, \qquad y = \frac{af - ec}{ad - bc}, $$

and describe each numerator as a determinant. Verify the rule on the opening system.

Show solutionHide solution

By the uniqueness theorem the solution is $A^{-1}(e, f) = \frac{1}{ad - bc}\begin{pmatrix} d & -b \\ -c & a \end{pmatrix}\begin{pmatrix} e \\ f \end{pmatrix} = \frac{1}{ad - bc}\,(de - bf,\ -ce + af)$, which is the claim. The numerator of $x$ is $\det\begin{pmatrix} e & b \\ f & d \end{pmatrix}$, the determinant of $A$ with its first column replaced by the target, and the numerator of $y$ is $\det\begin{pmatrix} a & e \\ c & f \end{pmatrix}$, with the second column replaced. For $3x + y = 5$, $x + 2y = 3$: $x = \frac{5 \cdot 2 - 1 \cdot 3}{5} = \frac75 = 1.4$ and $y = \frac{3 \cdot 3 - 5 \cdot 1}{5} = \frac45 = 0.8$.

Shared definitions used by this lesson's figures
# house kit: prepended to every essay figure after the std imports

# palette. AZURE and EMBER are the two actors, LEAF marks an answer, ROSE a problem
let PAPER = [1, 1, 1, 1]
let INK = [0.08, 0.09, 0.11, 1]
let SLATE = [0.40, 0.44, 0.50, 1]
let MIST = [0.85, 0.86, 0.88, 1]
let AZURE = [0.13, 0.42, 0.68, 1]
let EMBER = [0.89, 0.42, 0.12, 1]
let LEAF = [0.13, 0.55, 0.36, 1]
let ROSE = [0.78, 0.22, 0.24, 1]
let PLUM = [0.47, 0.30, 0.66, 1]
let GOLD = [0.85, 0.62, 0.08, 1]

background = PAPER

# an opaque pastel of col; use for fills so overlaps do not darken
let tint = |col, amount = 0.18| [
    1 - (1 - col[0]) * amount,
    1 - (1 - col[1]) * amount,
    1 - (1 - col[2]) * amount,
    1
]

# text: Cap for labels, Note for quiet labels, Math for typeset maths
let Cap = |txt, size = 0.75, col = INK| color{col} Text(txt, size, "Charter")
let Note = |txt, size = 0.65| color{SLATE} Text(txt, size, "Charter")
let Math = |tex, size = 0.9, col = INK| color{col} Tex(tex, size)

# a paper rectangle to sit behind text that crosses lines
let Plate = |pos, size| center{pos} fill{PAPER} stroke{alpha{0} PAPER, 0} Rect(size)

# shapes with fill and stroke both set, so no stray black appears
let Pt = |pos, col = INK, r = 0.075| center{pos} fill{col} stroke{col, 1} Circle(r, 48)
let Ring = |pos, col = INK, r = 0.1, w = 3| center{pos} fill{PAPER} stroke{col, w} Circle(r, 48)
let Seg = |a, b, col = INK, w = 3| stroke{col, w} Line(a, b)
let Path = |pts, col = INK, w = 3| stroke{col, w} Polyline(pts)
let Region = |pts, col| fill{col} stroke{alpha{0} col, 0} Polygon(pts)
let Outline = |pts, col = INK, w = 3| fill{alpha{0} PAPER} stroke{col, w} Polygon(pts)
let Shape = |pts, col, amount = 0.18, w = 3| fill{tint(col, amount)} stroke{col, w} Polygon(pts)
let Disc = |pos, r, col, amount = 0.18, w = 3| center{pos} fill{tint(col, amount)} stroke{col, w} Circle(r, 96)
let Box = |pos, size, col, amount = 0.18, w = 3| center{pos} fill{tint(col, amount)} stroke{col, w} Rect(size)
# a line from a to b ending in a small solid arrowhead
let Tip = |a, b, col = INK, w = 3, head = 0.17| {
    let d = normalize([b[0] - a[0], b[1] - a[1], 0])
    let n = [-d[1], d[0], 0]
    let base = [b[0] - d[0] * head, b[1] - d[1] * head, 0]
    return [
        stroke{col, w} Line(a, base),
        fill{col} stroke{col, 1} Polygon([
            b,
            [base[0] + n[0] * head * 0.42, base[1] + n[1] * head * 0.42, 0],
            [base[0] - n[0] * head * 0.42, base[1] - n[1] * head * 0.42, 0]
        ])
    ]
}

# plots. a frame is [x0, x1, y0, y1, centre, width, height]: a data window and the scene box it fills
let Frame = |x0, x1, y0, y1, c = [0, 0, 0], w = 6.4, h = 3.6| [x0, x1, y0, y1, c, w, h]
let fx = |fr, x| fr[4][0] + (x - (fr[0] + fr[1]) / 2) * fr[5] / (fr[1] - fr[0])
let fy = |fr, y| fr[4][1] + (y - (fr[2] + fr[3]) / 2) * fr[6] / (fr[3] - fr[2])
let at = |fr, x, y| [fx(fr, x), fy(fr, y), 0]

# axes through the data origin (or the nearest edge of the window), with optional names
let Axes = |fr, x_name = "", y_name = "", col = SLATE| {
    let ox = clamp(fr[0], 0, fr[1])
    let oy = clamp(fr[2], 0, fr[3])
    var parts = [
        Tip(at(fr, fr[0], oy), [fx(fr, fr[1]) + 0.25, fy(fr, oy), 0], col, 2.5, 0.15),
        Tip(at(fr, ox, fr[2]), [fx(fr, ox), fy(fr, fr[3]) + 0.25, 0], col, 2.5, 0.15)
    ]
    if (x_name != "") {
        parts .= center{[fx(fr, fr[1]) + 0.5, fy(fr, oy), 0]} Math(x_name, 0.8, col)
    }
    if (y_name != "") {
        parts .= center{[fx(fr, ox), fy(fr, fr[3]) + 0.5, 0]} Math(y_name, 0.8, col)
    }
    return parts
}

# tick marks with numbers at the listed data values
let XTicks = |fr, xs, col = SLATE, places = 0| block {
    let oy = fy(fr, clamp(fr[2], 0, fr[3]))
    for (x in xs) {
        . Seg([fx(fr, x), oy - 0.07, 0], [fx(fr, x), oy + 0.07, 0], col, 2)
        . center{[fx(fr, x), oy - 0.33, 0]} Math(to_string(x, places), 0.72, col)
    }
}
let YTicks = |fr, ys, col = SLATE, places = 0| block {
    let ox = fx(fr, clamp(fr[0], 0, fr[1]))
    for (y in ys) {
        . Seg([ox - 0.07, fy(fr, y), 0], [ox + 0.07, fy(fr, y), 0], col, 2)
        . center{[ox - 0.36, fy(fr, y), 0]} Math(to_string(y, places), 0.72, col)
    }
}

# faint grid lines at the listed data values
let GridLines = |fr, xs, ys, col = MIST| block {
    for (x in xs) {
        . Seg(at(fr, x, fr[2]), at(fr, x, fr[3]), col, 1.5)
    }
    for (y in ys) {
        . Seg(at(fr, fr[0], y), at(fr, fr[1], y), col, 1.5)
    }
}

# the graph of f over [a, b], drawn in the frame. values are clamped to the window
let Graph = |fr, f, a, b, col = AZURE, w = 4, n = 160|
    stroke{col, w} Polyline(map(sample(a, b, n), |x| at(fr, x, clamp(fr[2], f(x), fr[3]))))

# the region between the graph of f and the x axis over [a, b]
let AreaUnder = |fr, f, a, b, col = AZURE, amount = 0.2, n = 80| {
    var pts = [at(fr, a, 0)]
    for (x in sample(a, b, n)) {
        pts .= at(fr, x, clamp(fr[2], f(x), fr[3]))
    }
    pts .= at(fr, b, 0)
    return fill{tint(col, amount)} stroke{alpha{0} col, 0} Polygon(pts)
}

# vectors are pairs [x, y]. a board is [o, u, x0, x1, y0, y1]: the scene point of the origin,
# the unit length, and the window of whole numbers that is drawn
let Board = |o, u, x0, x1, y0, y1| [o, u, x0, x1, y0, y1]
let P = |pl, v| [pl[0][0] + pl[1] * v[0], pl[0][1] + pl[1] * v[1], 0]
let add = |v, w| [v[0] + w[0], v[1] + w[1]]
let times = |c, v| [c * v[0], c * v[1]]
# matrices are [a, b, c, d] with rows (a b) and (c d), so the columns are (a, c) and (b, d)
let IDENT = [1, 0, 0, 1]
let apply = |m, v| [m[0] * v[0] + m[1] * v[1], m[2] * v[0] + m[3] * v[1]]
let blend = |m, n, t| [
    m[0] + (n[0] - m[0]) * t,
    m[1] + (n[1] - m[1]) * t,
    m[2] + (n[2] - m[2]) * t,
    m[3] + (n[3] - m[3]) * t
]
let GRIDC = tint(AZURE, 0.42)
# faint gridlines, both axes, and numbers along the bottom and left edges every `step`
let Ground = |pl, step = 1, mult = 1| {
    var out = []
    let lo = P(pl, [pl[2], pl[4]])
    let hi = P(pl, [pl[3], pl[5]])
    for (x in range(pl[2], pl[3] + 1)) {
        let sx = P(pl, [x, 0])[0]
        out .= Seg([sx, lo[1], 0], [sx, hi[1], 0], MIST, 1.5)
        if (mod(x, step) == 0) {
            out .= center{[sx, lo[1] - 0.27, 0]} Math(to_string(x * mult), 0.72, SLATE)
        }
    }
    for (y in range(pl[4], pl[5] + 1)) {
        let sy = P(pl, [0, y])[1]
        out .= Seg([lo[0], sy, 0], [hi[0], sy, 0], MIST, 1.5)
        if (mod(y, step) == 0) {
            out .= center{[lo[0] - 0.38, sy, 0]} Math(to_string(y * mult), 0.72, SLATE)
        }
    }
    if (pl[4] <= 0 and pl[5] >= 0) {
        out .= Seg(P(pl, [pl[2], 0]), P(pl, [pl[3], 0]), SLATE, 2.5)
    }
    if (pl[2] <= 0 and pl[3] >= 0) {
        out .= Seg(P(pl, [0, pl[4]]), P(pl, [0, pl[5]]), SLATE, 2.5)
    }
    return out
}
# the part of the segment from scene point p to q that lies in the box lo..hi
let ClipSeg = |p, q, lo, hi, col, w| {
    let d = [q[0] - p[0], q[1] - p[1]]
    var t0 = 0
    var t1 = 1
    for (k in [0, 1]) {
        if (abs(d[k]) < 0.00001) {
            if (p[k] < lo[k] - 0.0001 or p[k] > hi[k] + 0.0001) {
                t1 = -1
            }
        }
        if (abs(d[k]) >= 0.00001) {
            let ta = (lo[k] - p[k]) / d[k]
            let tb = (hi[k] - p[k]) / d[k]
            t0 = max(t0, min(ta, tb))
            t1 = min(t1, max(ta, tb))
        }
    }
    if (t1 - t0 < 0.002) {
        return []
    }
    return stroke{col, w} Line(
        [p[0] + t0 * d[0], p[1] + t0 * d[1], 0],
        [p[0] + t1 * d[0], p[1] + t1 * d[1], 0]
    )
}
# a segment between two points of the board, cut off at the window
let Cut = |pl, a, b, col = SLATE, w = 2|
    ClipSeg(P(pl, a), P(pl, b), P(pl, [pl[2], pl[4]]), P(pl, [pl[3], pl[5]]), col, w)
# the whole-number grid after the matrix m: lines along the first column in col_a, along the second in col_b
let Lines = |pl, m, col_a = GRIDC, col_b = GRIDC, n = 8| block {
    for (k in range(-n, n + 1)) {
        var w = 1.8
        if (k == 0) {
            w = 3
        }
        . Cut(pl, apply(m, [-n, k]), apply(m, [n, k]), col_a, w)
        . Cut(pl, apply(m, [k, -n]), apply(m, [k, n]), col_b, w)
    }
}
# an arrow between two points of the board
let Vec = |pl, a, b, col = INK, w = 4.5, head = 0.2| {
    let p = P(pl, a)
    let q = P(pl, b)
    if (sqrt((q[0] - p[0]) ^ 2 + (q[1] - p[1]) ^ 2) < head * 1.3) {
        return Seg(p, q, col, w)
    }
    return Tip(p, q, col, w, head)
}
# transform the grid: the matrix is t of the way from m0 to m1; the first basis arrow is blue, the second orange
let Warp = |pl, m0, m1, t| {
    let m = blend(m0, m1, t)
    return [
        Lines(pl, m),
        Vec(pl, [0, 0], [m[0], m[2]], AZURE),
        Vec(pl, [0, 0], [m[1], m[3]], EMBER)
    ]
}
let Dash = |a, b, col = SLATE, w = 2.5| stroke{col, w} dashed{[0.1, 0.08]} Line(a, b)
let clean = |x| {
    if (abs(x) < 0.005) {
        return 0
    }
    return x
}
# a 2x2 matrix readout with brackets, first column blue and second orange
let MatBox = |c, m, places = 1, s = 0.9| {
    let dx = 0.5
    let dy = 0.3
    let bx = 1.0
    let by = 0.62
    let lip = 0.13
    let q = |x, y| [c[0] + x, c[1] + y, 0]
    return [
        stroke{INK, 2.5} Polyline([q(-bx + lip, by), q(-bx, by), q(-bx, -by), q(-bx + lip, -by)]),
        stroke{INK, 2.5} Polyline([q(bx - lip, by), q(bx, by), q(bx, -by), q(bx - lip, -by)]),
        center{q(-dx, dy)} scale{s} color{AZURE} Number(clean(m[0]), places),
        center{q(dx, dy)} scale{s} color{EMBER} Number(clean(m[1]), places),
        center{q(-dx, -dy)} scale{s} color{AZURE} Number(clean(m[2]), places),
        center{q(dx, -dy)} scale{s} color{EMBER} Number(clean(m[3]), places)
    ]
}
let matmul = |m, n| [
    m[0] * n[0] + m[1] * n[2],
    m[0] * n[1] + m[1] * n[3],
    m[2] * n[0] + m[3] * n[2],
    m[2] * n[1] + m[3] * n[3]
]
# an F, so that turning and mirroring can be told apart
let FPTS = [[0.4, 0.3], [0.8, 0.3], [0.8, 1.1], [1.3, 1.1], [1.3, 1.5], [0.8, 1.5], [0.8, 1.9], [1.6, 1.9], [1.6, 2.3], [0.4, 2.3]]
let FShape = |pl, m, col = LEAF| Shape(map(FPTS, |p| P(pl, apply(m, p))), col, 0.22, 2.5)
let det = |m| m[0] * m[3] - m[1] * m[2]
# lesson 7: linear systems
let A7 = [3, 1, 1, 2]
let A7INV = [0.4, -0.2, -0.2, 0.6]
let Z7 = [2, 4, 1, 2]
let BT = [5, 3]
let SOL = [1.4, 0.8]
let Bd = Board([-2.66, -0.95, 0], 0.64, -1, 6, -1, 4)
let B2 = Board([-1.94, -0.24, 0], 0.68, -2, 5, -2, 3)
let RX = 2.6
let mag = |v| sqrt(v[0] * v[0] + v[1] * v[1])
let Arrows = |pl, m| [
    Vec(pl, [0, 0], [m[1], m[3]], EMBER),
    Vec(pl, [0, 0], [m[0], m[2]], AZURE)
]
# the line p x + q y = r for a row [p, q, r] that passes through the board point `through`
let RowLine = |pl, r, through, col| {
    let k = 20 / mag([r[1], r[0]])
    let d = [r[1] * k, -r[0] * k]
    return Cut(pl, [through[0] - d[0], through[1] - d[1]], add(through, d), col, 3.5)
}
let fmt = |v| {
    if (abs(v - round(v)) < 0.001) {
        return to_string(round(clean(v)), 0)
    }
    return to_string(v, 1)
}
# an augmented matrix [r1; r2] with a bar before the last column; row 1 blue, row 2 orange
let Aug = |c, r1, r2, s = 0.95| {
    let q = |x, y| [c[0] + x, c[1] + y, 0]
    let xs = [-0.72, -0.08, 0.72]
    var out = [
        stroke{INK, 2.5} Polyline([q(-1.07, 0.62), q(-1.2, 0.62), q(-1.2, -0.62), q(-1.07, -0.62)]),
        stroke{INK, 2.5} Polyline([q(1.07, 0.62), q(1.2, 0.62), q(1.2, -0.62), q(1.07, -0.62)]),
        Seg(q(0.3, 0.55), q(0.3, -0.55), SLATE, 2)
    ]
    for (k in [0, 1, 2]) {
        out .= center{q(xs[k], 0.3)} Math(fmt(r1[k]), s, AZURE)
        out .= center{q(xs[k], -0.3)} Math(fmt(r2[k]), s, EMBER)
    }
    return out
}