linearly

Lecture 7.5

The Null Space

Add two solutions of Ax = 0 and you get another solution. Add two solutions of Ax = b and you do not. That gap is what makes one of them a subspace, and elimination hands you a basis for it.

147 slides / MIT 18.06, Lectures 6 to 7 / Strang §3.2–3.3

Slide 1 of 147
1 / 147

The idea in one sentence

The vectors a matrix sends to zero form a flat space through the origin, and one pass of elimination hands you a basis for it.

Two receipts

A shop sells two items. The first costs one dollar, the second costs two. A basket is a pair of counts x=(x1,x2)x = (x_1, x_2), and returns are allowed, so a count is any real number. The till computes

Ax=[12][x1x2]=x1+2x2.Ax = \begin{bmatrix} 1 & 2 \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} = x_1 + 2x_2 .

Two questions, same AA, different targets. Which baskets total six dollars? Which baskets total nothing? Both answers are infinite sets of points, and both are lines in the plane. They look like twins.

They are not. One of those lines is a subspace and the other is not, and everything this course does with solutions rests on that difference. Lecture 7 gave you the test: a subspace holds the zero vector, and it survives scaling and addition. Point the test at both lines.

Add two answers together

Two baskets that total six: u=(6,0)u = (6, 0) and v=(0,3)v = (0, 3). Check them against the till. Six items of the first kind cost 6+0=66 + 0 = 6. Three of the second cost 0+6=60 + 6 = 6.

Now put both baskets into one cart. The counts add, so the combined basket is u+v=(6,3)u + v = (6, 3), and the till says 6+6=126 + 6 = 12. Twelve dollars. The sum of two six-dollar baskets is not a six-dollar basket. Doubling fails for the same reason: 2u=(12,0)2u = (12, 0) costs twelve.

Two baskets that total nothing: p=(2,1)p = (2, -1), which buys two of the first item and returns one of the second, and q=(6,3)q = (-6, 3), which returns six and buys three. The till says 22=02 - 2 = 0 and 6+6=0-6 + 6 = 0. Add them: p+q=(4,2)p + q = (-4, 2), and the till says 4+4=0-4 + 4 = 0. Still nothing. Scale pp by any number you like and the total stays at zero, because scaling the basket scales the receipt.

pqp + q0zero dollarsadding stays on the lineuvu + v0six dollarstwelve dollarsadding leaves the line
Fig. 1 

Left: the baskets costing nothing. The green line runs through the origin, and the sum of two of its points is another of its points. Right: the baskets costing six. The orange line misses the origin, and adding two of its points lands you on the twelve-dollar line above it. The blue arrow is the addition in both panels.

The picture says it faster than the algebra. Adding two arrows on the right pushes you outward, away from the line you started on. On the left the line already runs through the origin, so pushing outward along it lands you back on it. That is the whole difference.

The set that misses the origin

The zero-dollar line contains the origin: the empty basket costs nothing. The six-dollar line does not, since the empty basket does not cost six dollars. That alone disqualifies it, because every subspace contains the zero vector.

A flat set pushed off the origin like this is called an affine set. It can have any dimension, and it is perfectly straight. Neither of those saves it. An affine set is a subspace only when the push is zero. The six-dollar line is the zero-dollar line shifted by any single six-dollar basket. Shift by u=(6,0)u = (6,0) or by v=(0,3)v = (0,3) and you land on the same line.

Why Ax = 0 always gives a subspace

Nothing above depended on the numbers 1 and 2. Take any matrix AA, and let xx and yy be two vectors it sends to zero. Then

A(x+y)=Ax+Ay=0+0=0,A(cx)=c(Ax)=c0=0.A(x + y) = Ax + Ay = 0 + 0 = 0, \qquad A(cx) = c\,(Ax) = c\,0 = 0 .

Both lines use only the property that AxAx distributes over sums and scalars. And A0=0A0 = 0 for every matrix, so the zero vector is always in. The closure test passes, for every AA ever written down.

This set has a name. For an mm by nn matrix AA, the null space N(A)N(A) is the set of all xx with Ax=0Ax = 0. It is also called the kernel. Since xx has nn entries, N(A)N(A) lives inside Rn\R^n, on the input side. The column space C(A)C(A) from Lecture 7 lives inside Rm\R^m, on the output side. Two spaces in two different rooms, and mixing up which room is which is the most common early mistake in this subject.

The solution set of Ax=bAx = b for a nonzero bb gets no such name, because it is not a subspace. It is an affine set, and Lecture 8 shows exactly which shift produces it.

Which columns carry new information

Time to compute a null space instead of guessing one. Start from a small matrix and write it twice, with the second copy doubled:

A=[122438616].A = \begin{bmatrix} 1 & 2 & 2 & 4 \\ 3 & 8 & 6 & 16 \end{bmatrix} .

Call this the doubled-columns matrix. Column 3 is twice column 1, and column 4 is twice column 2. So only two of the four columns carry new information.

That redundancy is already a null vector in disguise. Column 3 minus twice column 1 is the zero vector. Write down the recipe for that cancellation, one coefficient per column, and what you have written down is a solution of Ax=0Ax = 0.

122438616column 4 is twice column 2column 3 is twice column 1c₃ − 2c₁ = 0, so s₁ = (−2, 0, 1, 0)c₄ − 2c₂ = 0, so s₂ = (0, −2, 0, 1)
Fig. 2 

The two tinted columns are the repeats, and the blue arcs say what they repeat. Every redundant column is a null vector waiting to be written down: read the cancellation as a list of coefficients and you have a solution of Ax=0Ax = 0 before any elimination happens.

Check it by hand: 2(1,3)+(2,6)=(0,0)-2(1,3) + (2,6) = (0,0). The other pair cancels the same way. What follows is the machine that finds both vectors without needing you to spot anything.

Run elimination. Subtract 3 times row 1 from row 2 to reach the echelon form UU. Then divide row 2 by its pivot and clear the entry above it to reach the reduced row echelon form RR.

1224386161224020410200102AURc₁c₂2c₁2c₂eliminatereducepivotfree
Fig. 3 

One elimination step, then one cleanup step. Yellow rings the pivots and cyan tints the free columns, a pairing that holds for the rest of the chapter. Columns 1 and 2 hold a pivot; columns 3 and 4 do not, and their variables are free to be anything.

A column of RR that holds a pivot is a pivot column, and its variable is determined. A column with no pivot is a free column, and its variable can be set to any number you want. The count of pivots is the rank rr, so the count of free columns is nrn - r. Here r=2r = 2 and n=4n = 4, so two of the four columns are free, and the null space has dimension two for exactly that reason.

Elimination did not disturb the answer. Every row step is multiplication on the left by an invertible matrix EE. If Ax=0Ax = 0 then EAx=0EAx = 0, and if EAx=0EAx = 0 then multiplying by E1E^{-1} brings back Ax=0Ax = 0. So

N(A)=N(U)=N(R).N(A) = N(U) = N(R) .
AURreversiblereversibleN(A) = N(U) = N(R)the same sheet, spanned by s₁ and s₂
Fig. 4 

Three different matrices, one shared null space. Because every step between them can be undone, no vector enters or leaves the solution set along the way, which is why it is safe to hunt for N(A)N(A) in the tidiest of the three.

The block machine

Suppose the pivot columns come first, so RR splits into an identity block beside a leftover block:

R=[IF],R = \begin{bmatrix} I & F \end{bmatrix},

where II is rr by rr and FF is rr by nrn - r. Split the unknown the same way. Write yy for the pivot entries of xx and zz for the free entries. Then Rx=0Rx = 0 reads

Iy+Fz=0y=Fz.I y + F z = 0 \qquad\Longrightarrow\qquad y = -F z .

That is the whole algorithm. Pick the free entries, and the pivot entries follow. The cleanest picks are the columns of the identity, one free variable switched on at a time. Stack those choices side by side and the answers stack with them:

N=[FI],RN=[IF][FI]=F+F=0.N = \begin{bmatrix} -F \\ I \end{bmatrix}, \qquad R N = \begin{bmatrix} I & F \end{bmatrix} \begin{bmatrix} -F \\ I \end{bmatrix} = -F + F = 0 .
10200102−200−210010000RN0IF−FI=the top block cancelsthe bottom one
Fig. 5 

The block machine, drawn on the doubled-columns example. RR is the identity beside FF, yellow half and cyan half, and NN is F-F stacked on the identity. Multiply and the two halves cancel exactly.

For the doubled-columns matrix the leftover block is F=[2002]F = \begin{bmatrix} 2 & 0 \\ 0 & 2 \end{bmatrix}, so

N=[20021001],s1=(2,0,1,0),s2=(0,2,0,1).N = \begin{bmatrix} -2 & 0 \\ 0 & -2 \\ 1 & 0 \\ 0 & 1 \end{bmatrix}, \qquad s_1 = (-2, 0, 1, 0), \qquad s_2 = (0, -2, 0, 1).

These are the two vectors you guessed from looking at the columns. The columns of NN are called the special solutions, one per free column, and every vector in N(A)N(A) is a combination of them. That is what makes them a basis, and it is why dimN(A)=nr\dim N(A) = n - r.

−20100−201s₁s₂x₁x₂x₃x₄x₁x₂x₃x₄switch on x₃, leave x₄ offswitch on x₄, leave x₃ offA s₁ = (0, 0)A s₂ = (0, 0)the dashed box is what you choose; the rest is forced
Fig. 6 

One free variable at a time. Set the free entries inside the dashed box, and y=Fzy = -Fz fills in the pivot entries above. Two free columns give two special solutions.

python
import numpy as np

A = np.array([[1., 2., 2., 4.], [3., 8., 6., 16.]])
U = A.copy(); U[1] -= 3 * U[0]                  # one elimination step
R = U.copy(); R[1] /= 2; R[0] -= 2 * R[1]       # clear above the second pivot
print(R)                     # [[1. 0. 2. 0.]
                             #  [0. 1. 0. 2.]]

F = R[:, 2:]                                    # the free columns of R
N = np.vstack([-F, np.eye(2)]) + 0.0            # the block machine
print(N.T)                   # [[-2.  0.  1.  0.]   <- s1
                             #  [ 0. -2.  0.  1.]]  <- s2
print(A @ N)                 # [[0. 0.]
                             #  [0. 0.]]

# The computer's own answer, from the SVD, spans the same sheet.
_, s, Vt = np.linalg.svd(A)
print(s)                     # [19.7419204   0.50653633]  two nonzero: rank 2
ns = Vt[2:].T                # the last n - r right singular vectors
print(np.linalg.norm(A @ ns))                 # 2.06e-15
P = ns @ ns.T                                 # project s1 onto that sheet
print(np.linalg.norm(P @ N[:, 0] - N[:, 0]))  # 3.69e-15: it does not move

The last three lines are the interesting part. The SVD returns a completely different-looking basis for the null space, full of numbers like 0.40.4 and 0.8-0.8. Project s1s_1 onto the sheet that basis spans and s1s_1 does not move, which means both bases describe the same flat sheet. A subspace does not care which basis you hand it.

When the pivots are scattered

The tidy split R=[IF]R = \begin{bmatrix} I & F \end{bmatrix} assumed the pivot columns come first. They usually do not. Nothing important changes: the free variables still go in the free slots, and each pivot entry is still read off from the free column with its sign flipped.

102050130600017−2−3100−5−60−71Rfreefrees₁s₂the 1 goes in the free slot, and thatcolumn comes back with a flipped sign
Fig. 7 

Pivots in columns 1, 2 and 4. To build the special solution for column 3, put a 1 in slot 3 and a 0 in slot 5, then copy column 3 of RR into the pivot slots with the sign flipped. Check it: 2+2=0-2 + 2 = 0 on the first row, 3+3=0-3 + 3 = 0 on the second, and 0=00 = 0 on the third.

Compare the two special solutions with the free columns of RR. Column 3 is (2,3,0)(2, 3, 0) and s1s_1 carries 2-2 and 3-3 in the pivot slots. Column 5 is (5,6,7)(5, 6, 7) and s2s_2 carries 5-5, 6-6 and 7-7 in the same slots. The recipe is the one line from before, y=Fzy = -Fz, written out by hand.

What a null space looks like

Two free columns for the doubled-columns matrix means two knobs, which means a flat two-dimensional sheet of solutions sitting inside R4\R^4. Every point of that sheet is sent to the single point 00 in R2\R^2. Nothing on the sheet survives the trip.

R⁴A0N(A)dim N(A) = n − r = 4 − 2 = 2
Fig. 8 

The null space of the doubled-columns matrix is a flat two-dimensional sheet inside R4\R^4, and every point on it lands on the single point 00 in R2\R^2. The sheet runs through the origin, which is what makes it a subspace.

You cannot draw R4\R^4, so draw the sheet instead. Both knobs turn independently, the point wanders over the whole sheet, and the readout on the far side never leaves zero. Turn them yourself:

Try it. Turn the two free variables
s₁s₂0N(A), a flat sheet in R⁴

x = (-2.4, -1.4, 1.2, 0.7)

Ax = (0.00, 0.00)

The two pivot entries follow the two knobs, and the readout never leaves zero. Every point of the shaded sheet is a solution of Ax = 0.

Where this is going

You can now answer Ax=0Ax = 0 completely, for any matrix. Eliminate, find the pivots, put a 1 in each free slot in turn, and read the pivot entries off with a flipped sign.

The harder question is the one this lecture opened with and then set aside. When bb is not zero the solutions form an affine set, a shifted copy of the null space. Shifted by what? The answer is short: find any single solution, then add the whole null space to it. That single solution is called the particular solution, and the recipe is x=xp+xnx = x_p + x_n. Lecture 8 builds it, checks whether it exists at all, and sorts every matrix in the world into four cases by rank.