Systems of Linear Equations
Behind every Instagram feed, GPS route, and next-word prediction sits one humble object: . This unit earns you the single most useful mental picture in the course — a matrix is a machine that moves space — and a method that never lies: Gaussian elimination.
Why are we even talking about lines?
Open Instagram and scroll for ten seconds. The app just decided what to show you — which photo, which order, which ad. Behind that decision is a tower of math, and at the very bottom of the tower sits one humble object: a system of linear equations. Same story for the GPS routing you home, the camera autofocusing on a face, and a language model predicting the next word. Sooner or later, every one of them lands on something of the form .
But wait — look out the window. Roads curve. Light bends. The stock market zigzags. Almost nothing in real life is a straight line. So why does an entire branch of math — and the engine room of every ML model — obsess over linear things?
Three honest reasons. ① Linear problems can always be solved — not "solved if we're lucky." There's a recipe a computer can follow that either finds the answer or proves none exists. ② Up close, almost everything looks linear. The Earth is round, but your floor is flat. ③ You can see it — lines, planes, hyperplanes. Geometry you can draw on a napkin.
Reason ② is the profound one, and you shouldn't take it on faith. Test it yourself:
This zoom trick is the secret engine of this whole course. Calculus is "zoom in until it's linear." Training a neural network is "zoom in, solve the easy linear problem, take a small step, zoom in again" — a million times over. When we meet gradient descent in Unit 9, it will be exactly this widget, running in a loop.
The price of simplicity: a single straight line can't draw a circle or trace a stock chart. Linear things are simple, and simple things are limited. Machine learning's answer is to stack many linear pieces with a sprinkle of non-linear glue (a ReLU or sigmoid) between them — LEGO bricks: each brick is dumb and rectangular, but a million of them build a castle.
What is a vector, really?
The slides say it precisely: linear algebra is the study of vectors and the rules for manipulating them. But a vector is not some mysterious arrow floating in an abstract space. A vector is just an ordered list of numbers — plus the promise that adding two lists, or scaling a list, gives you back the same kind of object. (That promise has a name — closure — and it's the seed of the "vector space" idea that Unit 2 grows into.)
Lists you already use every day: a house in a dataset is a vector . A photo is a vector — one number per pixel, hundreds of thousands of them. A word inside a modern language model is a vector, the famous embedding. Even a polynomial can be treated as a vector — its list of coefficients. Even you, in your bank's risk model, are a vector.
Which of these can legitimately be treated as a vector?
A small problem you can solve by hand
You run a workshop making three furniture kits — chairs, tables, cabinets. Each kit consumes wood, labor, machine time and shipping effort. Today you have exactly 9 units of wood, 8 hours of labor, 7 hours of machine time, 11 units of shipping effort. How many of each kit should you make so that every resource is used exactly — nothing wasted, nothing short?
A factory manager solves a version of this every Monday. Translate it, one resource at a time — if you make chairs, tables, cabinets:
Before any theory — just play. Find the production plan with your hands:
How would you solve it on paper instead of by trial? You'd play a small game: take two equations, scale one, subtract. A variable disappears. Take equation 2 minus 2× equation 1:
The vanished — that is literally what eliminate means. Repeat until one variable stands alone, then substitute back up. Two moves. Everything fancy in this unit — matrices, Gaussian elimination, echelon form — is just these two moves, made automatic and made to scale.
One more thing worth noticing: that was four equations for three unknowns — an overdetermined system, which usually has no solution at all. The fact that one exists here means the four constraints happen to agree. Later in this unit you'll be able to detect that directly from the matrix, no guesswork. And when an overdetermined system doesn't have a solution — which is the everyday situation in machine learning — linear regression is exactly the art of finding the best approximate solution. That story starts here.
The three fates: zero, one, or infinity
A treasure is hidden on a flat island. Two friends each hand you a clue, and each clue happens to describe a straight line: "the treasure is somewhere on this line." Before you read on — what are all the ways this can play out?
There are exactly three, and you can generate all of them with your own hands:
A linear system can never have exactly two answers. Or seven. Or forty-two. Suppose you somehow found two different solutions and . Then their midpoint is a solution. So is every blend . The moment you have two, linearity hands you the whole line through them — infinitely many. Finite counts above one are simply not on the menu: zero, one, or infinity. Nothing else.
The same trichotomy appeared in the slides with three variables, where each equation is a plane in 3D. Add equations ① and ② : you get . If equation ③ says — contradiction, no solution. If ③ says — it's the other two in disguise, infinitely many, one for every choice of the free variable . And if ③ cuts through independently (say ), the three planes meet at one point . In dimensions the surfaces are called hyperplanes, we stop trying to draw them, and the story doesn't change: zero, one, or infinity. (In Section 13 you'll fly through those three planes in 3D and read each fate off a single number — the rank.)
Your classmate claims a linear system with exactly two solutions exists. What do you say?
Meet the matrix — a spreadsheet with superpowers
An matrix is a grid of numbers — rows, columns. If you've opened Excel, you've seen one. A row vector is a matrix, a column vector an matrix, and is the set of all such real grids. Strip our furniture problem of its variable names and plus signs, and keep only the numbers:
An entire system collapses into three letters: . This is more than shorthand — it's a doorway. The moment we stop seeing as "a stack of equations" and start seeing it as a thing that does something to , the whole subject opens up.
Adding two matrices: same shape, add cell by cell. Scaling by : multiply every cell. Multiplying two matrices is the strange one — row times column: for , , the product has . Trace it with your cursor:
Why this strange rule? Because matrices are secretly functions, and multiplication is secretly composition. Picture two photo filters: blurs, darkens. "Blur, then darken" is itself one combined filter — that filter is (read right-to-left: acts first). The row-times-column recipe is exactly the arithmetic that makes come out true. Matrix multiplication isn't an arbitrary convention — it's function composition wearing a numerical disguise.
And why does order matter? Socks then shoes ≠ shoes then socks. Rotate a page then slide it right ≠ slide then rotate. Same two operations, different order, different world: in general.
Facts you'll use forever: , , , , and for transposes — writing rows as columns, — the order-flipping rules , , . A few matrices to greet by name: the identity (the do-nothing filter), the zero matrix (destroy everything), diagonal matrices (stretch each axis independently), and symmetric matrices — the nicest citizens of linear algebra; Unit 4 is very fond of them.
Why (AB)ᵀ = BᵀAᵀ — the two-line argument from the slides
The entry of is (row of ) · (column of ). But row of is column of , and column of is row of . So the entry of is that same inner product — i.e. , which is precisely the statement . Notice the composition story hiding here too: undoing "socks then shoes" requires "shoes off, then socks off" — reversal flips order.
Without computing anything: equals…
Pause. Stare at Ax = b through three windows.
This is the most important section of the unit. One tiny system, three ways of seeing it — and switching between them at will is the single most useful skill in linear algebra. Whenever you're stuck, ask: which window would let me see this clearly? Our toy system:
Picture a vending machine. The chocolate bar is sitting in the tray; your job is to figure out which button code was punched in. Three questions decide everything — can the code be recovered? could multiple codes give the same item? could no code give it? — and all three are properties of the machine itself, not of the particular bar in the tray. Keep this view alive: 3Blue1Brown's Essence of Linear Algebra builds everything on it, and so will we.
In the column window, "solve " translates to…
A matrix is a Photoshop filter for space
Here's the picture to burn into your brain. Feed the two basis arrows and . Then is literally the first column of , and is the second column. That's not a coincidence — that's the entire game. Once you know where those two arrows land, linearity fixes everything else: . Four numbers, two arrows, one whole transformation of the plane.
And the determinant? The unit square (area 1) becomes a parallelogram; is the factor by which area got scaled — with a sign that records whether the plane got mirror-flipped. For a matrix, . Don't memorize first — watch first:
When det , three sentences become one fact told in three languages: ① is not invertible — no undo exists. ② The columns are linearly dependent — one is a blend of the others, so they bring no new direction. ③ Many inputs share one output — like a filter so aggressive that a hundred different photos come out identical. Get fluent at translating between the three; the exam (and real ML) will phrase it randomly. We'll meet this monster again under the name singular matrix — singular as in: a whole dimension's worth of vectors all collapsing into one point, the origin.
Up a dimension: the determinant is a volume
Nothing about the area story was special to 2D. In 3D, a matrix carries the unit cube (volume 1) to a slanted box — a parallelepiped — and is its signed volume. In dimensions, scales hyper-volume: the same idea, just past where drawing stops working. Grab the box below and spin it:
You compute for a matrix. Which of the following must be true?
The undo button — A⁻¹
If is "translate to French," is "translate back." The matrix that exactly reverses satisfies — do, then undo, and you're back where you started. If it exists, solving becomes one line: .
Does every square matrix have one? The slides settle it constructively for : pair with the candidate and multiply — everything cancels except . So
The determinant sits downstairs — divide by zero and the formula explodes. That's the algebra shaking hands with the geometry you just played with: the inverse exists iff space wasn't squashed flat. (Non-square matrices don't get a true inverse at all; their story — least squares — comes later in the course.)
For our toy : , so . Multiply by hand and confirm you land on — the same answer the two crossing lines gave you in Section 6. Three windows, one truth.
If is so beautiful, why do practitioners avoid computing it? Strike zero: it often doesn't exist at all. is only even a legal sentence when is square and full rank — a singular matrix has no inverse, a rectangular data matrix (the everyday case in ML: 10,000 examples × 50 features) never has one. Elimination keeps working in every one of those worlds; the inverse simply isn't there. And even when does exist, three more strikes. It's expensive — about the cost of solving the system, times a painful constant, and in ML can be . It's fragile — if is nearly singular, the inverse is full of huge almost-cancelling entries and floating-point noise blows up silently. It's wasteful — you wanted for one particular , not a master key for every apartment in the building. Industry rule: if you see np.linalg.inv(A) @ b in production, replace it with np.linalg.solve(A, b). Same answer, faster, more stable.
"Fragile" deserves to be felt, not just read. Here is a system whose true answer is always — and a dial that slides its matrix toward singularity:
You need for one system in production code. The professional move is…
A system with training wheels
Before building the general algorithm, the slides hand us a system so friendly it solves itself — if we look through the column window:
Two equations, four unknowns — underconstrained, so expect infinitely many solutions. But look at the first two columns: and . They can build any target instantly. So read straight off: take 42 of column 1, 8 of column 2, none of the rest —
Any other solutions? Here's the trick that unlocks the whole topic: you can add zero to a solution and it stays a solution — provided you write zero cleverly, as a blend of columns that cancels out. Column 3 is buildable from the first two: . In matrix form:
— and likewise for column 4: . Any multiple or is an invisible ingredient: add it to and the machine still outputs exactly . The complete answer:
You walk into a sandwich shop. House rule: every sandwich must contain bread and a protein — that's the constraint, the "" part. Beyond that, add any toppings you like. The particular solution is the pre-made base sandwich; the toppings are the wiggle directions. Every legal sandwich = base + your topping combination. In math clothes: the wiggle directions solve , their span is called the null space of , and
full solution set of = any one solution + null space of .
You will meet this formula again in linear regression, in optimization, and inside neural networks.
Two honest questions before moving on. Why isn't the particular solution unique? Because any point of the solution set can play the "anchor" role — the pre-made sandwich could just as well be a different sandwich from the menu. Why aren't the wiggle vectors unique? Any two independent blends of them span the same null space. What is unique is the solution set itself — the flat sheet they describe. But wait — those "invisible ingredients" just quietly became the most important object in this unit. Before we build the big algorithm, they deserve their own spotlight.
The null space — the machine's blind spot
A flashlight throws your hand's shadow onto a wall. The shadow-maker is a machine: 3D hand in, 2D shadow out. Now slide your hand straight along the beam, toward the flashlight. The shadow doesn't move. Not a pixel. That beam direction is invisible to the machine — motion along it produces zero change in the output. And because of that one invisible direction, any shadow you see could have been cast from infinitely many hand positions, all lined up along the beam.
Every matrix has a blind spot like that beam (sometimes it's just the trivial one). It has a name and a definition worth engraving:
— the null space: every input the machine sends to zero. (The subscript is a habit worth copying: for "null solution," the inputs that answer the homogeneous question .) It's never empty: always, so the origin is in every null space. The interesting question is whether anything else is — and here is exactly why you should care:
The null space is why solutions come in families. Suppose solves your problem: . Take any null vector and add it. Linearity does the rest:
The machine cannot tell and apart — they're perfect aliases, hand positions along the beam. And the converse seals it: if and both solve , then — any two solutions differ by a null vector. Nothing lives outside the family. Together, the two directions give the complete anatomy of every solution set:
solutions of all of — one anchor, plus the whole blind spot.
Watch the whole story run live. The system below is singular on purpose — (rank 1, second row a copy of the first), , null direction (check: ). Slide and keep one eye on each panel:
Put two perfectly correlated columns in your data matrix — say, temperature in °C and the same temperature in °F — and you have just manufactured a null space: some combination of those features is invisible to the model. Consequence: infinitely many weight vectors produce identical predictions, your regression "can't decide," and its coefficients can swing wildly without changing the fit. That is a null space attacking in the wild. Ridge regularization is, quite literally, the policy "among all aliases, pick the shortest " — you'll meet it later in the course, and you'll recognize it.
How big is the blind spot? Each independent null direction is one dimension of invisibility — a line, a plane, or more. The exact count will fall out of elimination in Sections 11–12: one free variable per missing pivot, . And when the blind spot is just ? Then aliases don't exist, and solutions — when they exist — are unique. You already know that case by its other names: full rank, , invertible.
solves (with ), and lies in . Which of these is guaranteed to be another solution?
Gaussian elimination — the polite-maker
Hand-elimination worked for chairs and tables, but a million-variable regression needs a procedure with no moods and no choices: same kind of step every time, guaranteed to finish, and a verdict — which of the three fates — at the end. That's what an algorithm is. Here it is.
First, glue and into one grid — the augmented matrix . Then use exactly three legal moves, each one an honest re-statement of the equations: ① swap two rows (re-order the equations); ② scale a row by (multiply both sides); ③ add a multiple of one row to another (add equal things to equal things). Each move is reversible, so the solution set never changes. We are not solving a different problem — we're rewriting the same problem until the answer becomes obvious. The target shape: pivots marching down-and-right in a staircase, zeros below — row-echelon form (REF).
Formally, a matrix is in row-echelon form when all-zero rows sit at the bottom, and each row's first non-zero entry — its pivot — lies strictly to the right of the pivot above, with only zeros beneath it. Variables owning a pivot column are basic (bound); the rest are free. And notice what the last row of the big example did for us: it distilled the entire system's fate into one sentence, "" — consistent only when . Elimination doesn't just solve systems; it diagnoses them.
Move ② lets you scale a row by any . Why exactly is forbidden?
RREF — hospital corners, and two magic tricks
REF is making your bed: sheets tucked, sleepable. Reduced row-echelon form is hospital corners: keep going until every pivot equals 1 and is the only non-zero entry in its column — sweep upward too. Pivot columns become canonical basis vectors, and the answers sit on the right of the bar, ready to read. Unlike REF (which depends on your route), RREF is unique — it's the matrix's fingerprint.
Trick 1: solving by inspection. Take this RREF from the slides:
The pivot columns (1, 3, 4) are "strong enough" to build the non-pivot columns (2, 5). Column 2 = 3×column 1, so 3·c₁ − 1·c₂ = 0 gives the solution . Column 5 = 3c₁ + 9c₃ − 4c₄, giving . Spot the pattern — copy the non-pivot column's recipe, then put a −1 in that column's own slot. Every free column donates one null-space direction, and the general solution is their span.
Now the full dish — an infinite-solutions system, cooked end to end. Same matrix, but with a target on the right:
Because the pivot columns are canonical basis vectors, the particular solution is read straight off the bar: put each right-hand entry into its pivot variable's slot, zeros for the free variables — . Bolt on the two null-space directions we just found, and the entire infinite family is:
The null space is not a bag of leftovers — it's a space. Check the closure promise from Section 2: if and , then and . Add two invisible ingredients, or scale one — still invisible. The null space passes the vector-space entrance exam, and its size is bookkept by a beautiful ledger: each free column donates exactly one direction, so
(here ) — the rank–nullity theorem in street clothes.
Every pivot is a rule that pins a variable down; every missing pivot is a freedom left over. Information used + freedom remaining = number of unknowns. In Unit 2 (Vector Spaces) the null space and column space graduate into first-class citizens — with bases, dimensions, and the full geometry. You've already met them; there you'll learn their language.
Trick 2: the inverse, for free. If is invertible, its RREF is itself. Now stack and row-reduce the left half to : the right half silently becomes . Why? Solving for each basis vector recovers column of — and the augmented block runs all of those systems at once: . Elimination "knows" how to invert — even though (Section 8!) you'll rarely ask it to.
Rank — one number that settles everything
Three friends in a group chat: whenever one speaks, the other two repeat it. Three people, one opinion — effectively a one-person chat. Rank counts the genuinely different voices in a matrix: the number of pivots that survive elimination — the number of truly independent directions its columns carry.
One digit can change everything:
In , row₃ − 2·row₂ + row₁ = 0 — one row is hiding inside the other two, an agreeing friend. Change the 9 to a 10 and the dependency snaps: three real voices. Headline fact: a square matrix is invertible rank columns independent. One fact, now four languages.
Here's the profound part. Think of a matrix as a message. Rank counts the words that aren't repeats — the genuinely non-redundant information it carries. And you can count from two different sides. The row rank asks: how many of the rows are independent rules (rules that aren't blends of other rules)? The column rank asks: how many of the columns are independent ingredients (directions the recipe can actually reach)? These are different questions about different objects — rows live in , columns in — and yet:
Row rank = column rank. Always. Every matrix, every shape, no exceptions — which is why we get away with saying just "rank." It's one of linear algebra's quiet miracles: the number of independent rules a matrix imposes equals the number of independent directions it can produce. (Elimination shows why: each pivot simultaneously certifies one independent row and one independent column — the staircase counts both at once.) Two ceilings follow instantly: rank can't exceed the number of rows, and can't exceed the number of columns, so . A matrix at that ceiling is called full rank — zero redundancy, every word in the message new.
And the collapse dictionary is now complete: rank below the ceiling area/volume crushed to 0 singular. Drop by one rank in 3D and the cube flattens to a sheet; by two, to a line — you watched exactly this in the volume machine of Section 7. Rank is how many dimensions survive the transformation.
And rank answers the existence question completely — the three lines the whole unit was building toward:
① At least one solution — i.e. lies in the column space; the recipe can be cooked.
② Exactly one ① holds and , the number of unknowns — no free variables, no wiggle room.
③ Infinitely many ① holds and — free variables exist, the null space is alive.
Watch all three lines come true in 3D. Same first two planes every time; only the third equation changes — and the rank chips tell each fate before your eyes do:
Elimination on a 3-unknown system leaves . What is the solution set?
with . For a given , how many solutions can have?
The whole story, in five lines
① Linear systems matter because the world is locally linear, and ML is stacks of linear pieces with non-linear glue. ② is three pictures at once — row rules, column recipe, machine — keep all three windows open. ③ is beautiful theory and poor practice: solve, don't inv. ④ Gaussian elimination → staircase → read off solutions, rank, inverse, and the system's fate. ⑤ Everything else this semester — LU, Cholesky, QR, even SVD — is a smarter flavor of the same elimination move.
One image: a matrix is a machine that moves space; solving asks which input the machine turned into that output. One method: elimination on until the staircase appears. One number: rank — the matrix's real dimension, and the judge of all three fates.
What's coming — every later method is elimination in disguise
| Method | In one sentence | Where |
|---|---|---|
| LU | Elimination, recorded — factor once, solve many b's cheaply. | Units 2–3 |
| Cholesky | Elimination exploiting symmetry — half the work. | Unit 4 |
| QR / least squares | Elimination by rotations — the right move when no exact solution exists; the math behind regression. | Units 3, 7 |
| Eigen / SVD | The deepest factorization: any matrix = rotation · stretch · rotation. Route to PCA. | Units 4–5, 12–13 |