Before this lesson:lesson 01 (matrices as maps, span,
basis, independence) and lesson 02 (rank, rank–nullity,
the four subspaces). Eigenvalues appear once, for detA=λ1⋯λn; here you only
need the definition Av=λv with v=0 (lesson 05
treats eigenvalues in full). Time: about 70 minutes, plus the notebook.
Three questions come up in almost every numerical method. Can I undo this map (inverse)? How
much does it change volumes (determinant)? What is the closest point in a subspace (projection)?
Least squares is a projection. Gaussian likelihoods and normalizing flows need logdet.
Attention scores and cosine similarity are dot products. And in practice you almost never form A−1.
Inverse.A−1 undoes A:A−1(Ax)=x. This is possible exactly when A loses
nothing. No nonzero input may go to 0 (otherwise two inputs give the same output), and every
output must be reached. For a square matrix these two conditions are the same, by rank–nullity:
dimN(A)=0⟺rankA=n⟺C(A)=Rn.
Interactive figure: loading…
Do it, then undo it. Press Apply A: the grid, the unit square and the letter F move to their
images. Then press Apply A⁻¹: everything returns, because A−1A=I. Now pick singular: det 0.
The magenta dots lie on one line x+N(A), and A sends all of them to the same point. No map
can send one point back to five, so A−1 does not exist.
Determinant in 2D. The columns (a,c) and (b,d) of A=(acbd)
span a parallelogram of area ∣ad−bc∣. The sign of detA=ad−bc is + if A keeps the
orientation (the turn from the first column to the second is counter-clockwise, as from e1 to
e2) and − if it makes a mirror image. Every area is multiplied by ∣detA∣. If
detA=0, the plane is squeezed onto a line or a point.
Interactive figure: loading…
Signed area. Drag the orange and blue columns. The
unit square becomes a parallelogram of area ∣detA∣, and the F inside it grows by the same
factor. Drag a2 to the other side of a1: the turn arrow reverses, the F becomes a mirror image
and detA<0. Make the columns parallel: the area is 0 and the plane collapses onto a line.
Quick check
A and B are 2×2 with detA=2 and detB=−3. What does AB do to the unit square?
Why.
AB means "first B, then A". B multiplies areas by 3 and mirrors the plane; A multiplies areas by 2 and keeps the orientation. So det(AB)=2⋅(−3)=−6: area 6, one mirror, orientation reversed. Determinants multiply; they do not add (2+(−3)=−1 is the tempting wrong step).
Dot product and projection.u⊤v=∥u∥∥v∥cosθ, where θ is the angle
between u and v. The projection p of b onto a line or a subspace is the foot of the
perpendicular from b: the error b−p is perpendicular to every vector of the subspace.
Section 3 shows both in figures.
A square n×n matrix A is invertible if there is a matrix A−1 with
A−1A=AA−1=I. The inverse is unique: if BA=I and AC=I, then
B=B(AC)=(BA)C=C.
Theorem (invertible matrix theorem). For a square n×n matrix A, these statements
are equivalent:
(a) A is invertible;
(b) N(A)={0}:Ax=0 only for x=0;
(c) rankA=n: elimination (with row exchanges) gives n nonzero pivots;
(d) the columns of A are independent, so they form a basis of Rn;
(e) C(A)=Rn:Ax=b has a solution for every b;
(f) Ax=b has exactly one solution for every b;
(g) detA=0;
(h) 0 is not an eigenvalue of A;
(i) A⊤ is invertible (so the rows are independent too);
(j) there is a B with BA=I, or there is a C with AC=I (one side is enough).
Lesson 08 adds one more: all singular values are positive. The short version: a square matrix is
invertible exactly when it loses no direction.
Proof of the main links
(a) ⇒ (b): if Ax=0, then x=A−1Ax=0.
(b) ⇔ (d) is the null-space test of lesson 01. (b) ⇔ (c) ⇔ (e) is rank–nullity:
dimN(A)=n−rankA and dimC(A)=rankA.
(e) and (b) give (f): a solution exists, and two solutions differ by a vector of N(A)={0}.
(e) ⇒ (a): choose cj with Acj=ej and set C=[c1⋯cn], so AC=I. Then
A(CA−I)=ACA−A=0, so every column of CA−I lies in N(A), which is {0} by
step 2. Hence CA=I too.
(b) ⇔ (h): a nonzero x with Ax=0=0⋅x is exactly an eigenvector for λ=0.
(c) ⇔ (g): detA=± (product of the pivots), shown below.
(j): BA=I gives (b) as in step 1; AC=I gives (e), because b=A(Cb) for every b.■
Theorem (one side is enough). If A and B are n×n and BA=I, then AB=I.
Proof.
BA=I gives N(A)={0}: if Ax=0, then x=BAx=B0=0.
A is square, so rank–nullity gives rankA=n and C(A)=Rn. So each
ej=Acj for some cj; with C=[c1⋯cn] we get AC=I.
B=B(AC)=(BA)C=C, so AB=AC=I.■
This needs a square matrix. For A=(10)(2×1) and
B=(10),BA=[1]=I1, but
AB=(1000)=I2. A tall matrix with independent columns
has left inverses, for example (A⊤A)−1A⊤, but no right inverse:
rank(AB)≤rankA<m.
Rules.(AB)−1=B−1A−1 (undo the last step first), (A⊤)−1=(A−1)⊤, and
(acbd)−1=ad−bc1(d−c−ba).
In practice: solve, do not invert. To solve Ax=b, factor A=LU once (about
32n3 flops, lesson 10) and do two triangular solves (2n2 flops). Forming A−1
costs about 2n3 flops, three times more. And x=A−1b is less accurate: its residual
∥b−Ax^∥ can be larger by a factor up to about κ(A), the condition number
(section 5 shows it).
Quick check
Which statement is not equivalent to "the n×n matrix A is invertible"?
Why.
Invertibility is about lost directions, not about single entries. (1111) has no zero entry but is singular (parallel columns), and I has many zero entries but is invertible. The other three are items (g), (b) and (e) of the theorem.
The determinant is the unique function of square matrices with three rules:
detI=1;
exchanging two rows flips the sign;
det is linear in each row separately (the other rows fixed).
Everything else follows from these rules:
two equal rows give det=0 (exchanging them changes nothing, but must flip the sign);
subtracting a multiple of one row from another does not change det (rule 3, then the
previous point);
a triangular matrix has det = product of its diagonal entries;
so elimination gives detA=± (product of the pivots), with − for an odd number of row
exchanges; hence detA=0⟺ a pivot is missing ⟺A is singular;
detA⊤=detA.
For 2×2 this gives ad−bc.
Determinant by elimination, step by step. Take
A=012214103.
The first pivot position holds 0, so exchange rows 1 and 2. One exchange: the sign flips.
102124013,det=−detA.
Row 3 − 2·row 1: (2,4,3)−(2,2,0)=(0,2,3). The determinant does not change.
Row 3 − row 2: (0,2,3)−(0,2,1)=(0,0,2). The determinant does not change.
Now U=100120012 is triangular: detU=1⋅2⋅2=4.
One exchange in total, so detA=(−1)1⋅4=−4.
Check by cofactor expansion along row 1: 0⋅(1⋅3−0⋅4)−2⋅(1⋅3−0⋅2)+1⋅(1⋅4−1⋅2)=0−6+2=−4 ✓.
Cofactor expansion costs about n! operations; libraries use the pivots of LU, about 32n3 flops.
Geometric meaning.∣detA∣ is the volume of the box (parallelepiped) spanned by the
columns: the image of the unit cube. Since detA⊤=detA, the rules also hold for columns,
and then they are the rules of volume: the unit cube has volume 1, stretching one edge by c
scales the volume by c, and a shear keeps base and height. The sign records orientation. Every
small cube is scaled by the same factor, so every region's volume is multiplied by ∣detA∣.
Theorem (product rule).det(AB)=detA⋅detB.
Proof.
If B is singular, so is AB(Bx=0 with x=0 gives ABx=0). Both sides are 0.
If detB=0, define D(A)=det(AB)/detB as a function of A.
D(I)=detB/detB=1: rule 1.
Row i of AB is (row i of A)B. So exchanging two rows of A exchanges the same rows of
AB, and D flips sign: rule 2.
Row i of AB depends linearly on row i of A, so D is linear in each row of A: rule 3.
The three rules fix the determinant, so D(A)=detA.■
The picture says the same: AB means "apply B, then A". Volumes are scaled by detB,
then by detA, and the signs multiply. Consequences: det(A−1)=1/detA;det(M−1AM)=detA;det(cA)=cndetA (each of the n rows is scaled by c).
Theorem (determinant = product of the eigenvalues). Let A be n×n with eigenvalues
λ1,…,λn, complex ones included, each repeated as often as its algebraic
multiplicity. Then detA=λ1λ2⋯λn and
trA=λ1+⋯+λn.
The idea: λ is an eigenvalue exactly when A−λI loses a direction, that is, when
det(A−λI)=0. This determinant is a polynomial in λ, the characteristic
polynomial, and its roots are the eigenvalues. Lesson 05
develops it; the proof below needs only these two facts. Check on a small case:
(4213) has eigenvalues 5 and 2 (section 4), and 5⋅2=10=detA.
Proof of detA=λ1⋯λn
λ is an eigenvalue ⟺A−λI is singular ⟺p(λ)=det(A−λI)=0.
p is a polynomial of degree n in λ with leading term (−λ)n (it comes from the
product of the diagonal entries).
Over C,p factors completely into its roots, the eigenvalues:
p(λ)=(λ1−λ)(λ2−λ)⋯(λn−λ). The leading term (−λ)n matches.
Put λ=0:detA=p(0)=λ1λ2⋯λn.■
The coefficient of λn−1 gives trA=λ1+⋯+λn in the same way:
in the product of the diagonal entries (A11−λ)⋯(Ann−λ) it is
(−1)n−1(A11+⋯+Ann), the other terms of p have degree at most n−2, and in the
factored form it is (−1)n−1(λ1+⋯+λn).
Numerics. The determinant is a bad test of near-singularity. det(0.1I100)=10−100,
but 0.1I is perfectly conditioned (κ=1).diag(105,10−5) has
det=1 but κ=1010. Use singular values to judge near-singularity (lesson 13), and
compute log∣detA∣ from a factorization (slogdet, or Cholesky) when you need it.
For u,v∈Rn: the dot product is u⊤v=∑iuivi, the norm is
∥v∥=v⊤v, and for nonzero u,v the angleθ∈[0,π] satisfies
cosθ=u⊤v/(∥u∥∥v∥). The vectors are orthogonal(u⊥v) if u⊤v=0.
The picture: a shadow. Drop a perpendicular from the tip of v onto the line through u. The
foot of the perpendicular is the shadow of v. Its signed length is ∥v∥cosθ, and
u⊤v=∥u∥⋅(∥v∥cosθ)=length of u×signed length of the shadow of v.
Interactive figure: loading…
Drag the orange tip u and the blue tip v.
The thick segment is the shadow of v on the line through u:aqua when u⊤v>0,magenta when u⊤v<0.
The readout compares u1v1+u2v2 with ∥u∥∥v∥cosθ. Notice that the shadow is never
longer than v itself: that is Cauchy–Schwarz. The two lengths are equal only when v lies on the
line through u (try opposite).
Cauchy–Schwarz:∣u⊤v∣≤∥u∥∥v∥, so the cosine lies in [−1,1] and the angle is
well defined. In the picture: a shadow is never longer than the vector that casts it. Proof for
v=0:0≤∥u−tv∥2=∥u∥2−2tu⊤v+t2∥v∥2 for every number t; put
t=u⊤v/∥v∥2 to get 0≤∥u∥2−(u⊤v)2/∥v∥2.
Pythagoras:∥u+v∥2=∥u∥2+2u⊤v+∥v∥2, so ∥u+v∥2=∥u∥2+∥v∥2⟺u⊥v.
Norm rules:∥v∥≥0 with ∥v∥=0 only for v=0;∥cv∥=∣c∣∥v∥;∥u+v∥≤∥u∥+∥v∥ (from Cauchy–Schwarz).
Nonzero, mutually orthogonal vectors are independent: take the dot product of
∑jcjqj=0 with qi to get ci∥qi∥2=0.
Let a=0 and b be vectors in Rm. The projection p=x^a is the point of the
line through a closest to b: the shadow of b, now as a vector.
The error e=b−x^a is orthogonal to a:a⊤(b−x^a)=0.
So x^=a⊤b/a⊤a and
p=a⊤aa⊤ba=Pb,P=a⊤aaa⊤.
P is m×m with rank 1, P⊤=P and P2=P.
Interactive figure: loading…
Drag the orange tip a and the black tip b. The
violet arrow p=x^a is the point of the line closest to b, and the
magenta error e=b−p meets the line at a right angle, so a⊤e=0.
The readout follows the two steps above. Try b on the line(e=0) and b ⟂ a(p=0).
Quick check
Project b=(1,1) onto the line through a=(1,0). What is p?
Why.
x^=a⊤b/a⊤a=1/1=1, so p=1⋅(1,0)=(1,0). The error e=b−p=(0,1) is perpendicular to a.(0,1) is the error, not the projection; (21,21) is the projection of (1,0) onto the line through (1,1), with the roles of a and b swapped.
Theorem (projection onto C(A)). Let A be m×n with independent columns, and
b∈Rm. The point of C(A) closest to b is p=Ax^, where x^ solves the
normal equationsA⊤Ax^=A⊤b. So p=Pb with
P=A(A⊤A)−1A⊤.
Derivation in four steps, then the proof that it is closest.
Write p with unknown coordinates.p lies in C(A), so p=Ax^ for some x^∈Rn.
Ask for a perpendicular error. The error e=b−Ax^ must be orthogonal to every column
aj of A:aj⊤(b−Ax^)=0 for j=1,…,n.
Stack the n equations. The rows of A⊤ are the aj⊤, so step 2 is
A⊤(b−Ax^)=0, that is, A⊤Ax^=A⊤b. (So e∈N(A⊤), the left null
space of lesson 02.)
Solve.A⊤A(n×n) is invertible, because rank(A⊤A)=rank(A)=n
(lesson 02: A⊤Ax=0 gives ∥Ax∥2=0, so Ax=0 and x=0). Hence
x^=(A⊤A)−1A⊤b and p=A(A⊤A)−1A⊤b=Pb.
p is the closest point. For any x,b−Ax=(b−p)+(p−Ax) with b−p⊥C(A) and
p−Ax∈C(A). Pythagoras gives ∥b−Ax∥2=∥b−p∥2+∥p−Ax∥2≥∥b−p∥2, with
equality only when Ax=p.■
For one column (n=1,A=a) these steps give back the line formula: A⊤A=a⊤a is a number.
Interactive figure: loading…
Project b onto a plane. The green patch is C(A) for the columns
a1=(1,0,1) and a2=(0,1,1) of section 4(c).
Drag the figure to rotate it, and move b with the sliders. The projection p
lies in the plane, and the error e always meets the plane at a right angle,
so A⊤e=0. Switch to a line for section 4(b), and to plane, the wrong way to see that the
sum of the two line projections misses p when a1⊤a2=0.
P⊤=P, because A⊤A is symmetric. A matrix with P2=P and P⊤=P is an
orthogonal projector.
I−P projects onto C(A)⊥=N(A⊤):(I−P)b=e.
The eigenvalues are 1 (on C(A)) and 0 (on N(A⊤)). So trP=rankP=n,
and detP=0 unless n=m (then P=I).
Orthonormal columns. If Q has orthonormal columns (Q⊤Q=I), then P=QQ⊤ and
p=∑i(qi⊤b)qi. The projection onto the span is the sum of the projections onto
the lines through the basis vectors (for every b) only when these vectors are mutually orthogonal.
Dependent columns. Then A⊤A is singular and the formula fails. The projection onto
C(A) still exists: use a basis of C(A), or P=AA+ with the pseudoinverse (lesson 08).
In practice you do not form the m×m matrix P, and you do not invert A⊤A: lesson 12
solves least squares with QR, because κ(A⊤A)=κ(A)2.
Quick check
P is an orthogonal projector: P2=P and P⊤=P. What does P2=P say in words?
Why.
P(Pb)=Pb: a point that is already in the subspace stays where it is. A projector onto a proper subspace is singular (it sends N(A⊤) to 0), so it is not its own inverse and not I. Its eigenvalues are 1 on the subspace and 0 on the orthogonal complement; P2=P only forces each eigenvalue to satisfy λ2=λ.
Answers to section 1. (1) Area 3. By the product rule ∣det(AB)∣=∣detA∣∣detB∣=6⋅21.
(2) Not in general: it holds for every b only if a1⊥a2. Section 4(c) shows a counterexample.
The unit square goes to the parallelogram spanned by (4,2) and (1,3), with area 10 and the
orientation kept. The eigenvalues solve λ2−(trA)λ+detA=λ2−7λ+10=0,
so λ=5,2: product 10=detA ✓, sum 7=trA ✓.
With the swap S=(0110)(detS=−1),AS=(1342) (the columns of A swapped) has
det(AS)=2−12=−10=detA⋅detS: same area, reversed orientation. (Pick columns
swapped in the signed-area figure.)
Quick check
Elimination on a 3×3 matrix A needs two row exchanges and gives the pivots 2,−1 and 3. What is detA?
Why.
detA=(−1)exchanges×(product of the pivots)=(+1)⋅(2⋅(−1)⋅3)=−6. Two exchanges flip the sign twice, so they cancel. 4 is the sum of the pivots, not the product. A negative pivot is still a pivot; only a missing (zero) pivot makes detA=0.
(b) Projection onto a line.a=(1,2,2),b=(3,0,3). Then a⊤b=3+0+6=9 and
a⊤a=9, so x^=1,p=(1,2,2) and e=b−p=(2,−2,1). Check:
a⊤e=2−4+2=0 ✓.
(c) Projection onto a plane.A=101011,b=(1,2,6).
Follow the four steps.
Step 1.p=Ax^ with unknown x^=(x^1,x^2).
Steps 2 and 3. The error must be perpendicular to both columns, which gives the normal
equations A⊤Ax^=A⊤b. They need A⊤A and A⊤b:
A⊤A=(2112),A⊤b=(78).
Step 4. Solve with the 2×2 inverse formula (detA⊤A=3):
x^=31(2−1−12)(78)=(23).
So p=Ax^=(2,3,5) and e=b−p=(−1,−1,1). Check: A⊤e=(−1+1,−1+1)=(0,0) ✓.
The plane is x3=x1+x2, with normal (1,1,−1), and e is parallel to that normal.
Pythagoras: ∥b∥2=41=∥p∥2+∥e∥2=38+3 ✓. The projection matrix is
P=A(A⊤A)−1A⊤=312−11−121112,trP=2=rankA.
Check P⊤=P and P2=P.P is symmetric: the (1,2) and (2,1) entries are both
−31, and so on. For P2, row 1 of P times column 1 of P is
91(2⋅2+(−1)(−1)+1⋅1)=96=32, the (1,1) entry of P; row 1 times
column 2 is 91(2⋅(−1)+(−1)⋅2+1⋅1)=−93=−31, the (1,2) entry. The
other entries work the same way (the code in section 5 checks all of them). And Pb=31(2−2+6,−1+4+6,1+2+12)=(2,3,5)=p ✓.
The wrong way. Project b onto each column separately and add:
27(1,0,1)+28(0,1,1)=(3.5,4,7.5)=(2,3,5). It fails because
a1⊤a2=1=0: the columns are not orthogonal.
The libraries check section 4. The notebook for this lesson has these cells and the exercises.
importnumpyasnp# (a) inverse, determinant, eigenvaluesA=np.array([[4.,1.],[2.,3.]])print(round(np.linalg.det(A),12))# 10.0print(np.round(10*np.linalg.inv(A),12))# [[ 3. -1.] [-2. 4.]]print(np.sort(np.linalg.eigvals(A).real))# [2. 5.]S=np.array([[0.,1.],[1.,0.]])# swap: det S = -1print(round(np.linalg.det(A@S),12))# -10.0# determinant by elimination (section 3): one row exchange, pivots 1, 2, 2M=np.array([[0.,2.,1.],[1.,1.,0.],[2.,4.,3.]])print(round(np.linalg.det(M),12))# -4.0# (c) projection onto C(A); lstsq returns the x-hat of the normal equationsA=np.array([[1.,0.],[0.,1.],[1.,1.]])b=np.array([1.,2.,6.])x_hat=np.linalg.lstsq(A,b,rcond=None)[0]p=A@x_hatprint(np.round(x_hat,12),np.round(p,12))# [2. 3.] [2. 3. 5.]print(np.abs(A.T@(b-p)).max()<1e-12)# True: e is orthogonal to C(A)P=A@np.linalg.pinv(A)# equals A (AᵀA)⁻¹ Aᵀ hereprint(np.allclose(P@P,P),np.allclose(P,P.T),round(np.trace(P),12))# True True 2.0# a tiny determinant does not mean "nearly singular"B=0.1*np.eye(100)print(np.linalg.det(B),np.linalg.cond(B))# about 1e-100, and 1.0print(np.linalg.slogdet(B))# sign 1.0, log|det| = -230.258...
And the reason to solve instead of invert, on the Hilbert matrix Hij=1/(i+j−1) of size 8
(κ≈1.5⋅1010):
Linear regression. The fitted values are y^=PXy with the "hat matrix"
PX=X(X⊤X)−1X⊤, the projector onto the span of the features. The residuals are
orthogonal to every feature, and trPX = the number of parameters.
Gaussian models.logN(x;μ,Σ) contains −21logdetΣ. Compute it as
2∑ilogLii from the Cholesky factor Σ=LL⊤ (lesson 07), never as
log(detΣ), which can underflow or overflow. Gaussian-process regression needs it at every
hyperparameter step.
Normalizing flows. For an invertible map z=f(x),logpX(x)=logpZ(f(x))+log∣detJf(x)∣. A general determinant costs O(n3), so
coupling layers (RealNVP, Glow) make Jf triangular: log∣detJf∣=∑ilog∣Jii∣ costs O(n).
Attention and embeddings. Attention scores are dot products q⊤k (scaled by
1/dk); cosine similarity of embeddings is cosθ=u⊤v/(∥u∥∥v∥).
ML for science: hard constraints. If a surrogate model must satisfy a linear conservation law
Cx=0 (for example a discrete mass balance, C with independent rows), you can enforce it
exactly by projecting the prediction onto N(C):x↦x−C⊤(CC⊤)−1Cx. This is
I−P with P the projector onto C(C⊤) (take A=C⊤ in the theorem). The same idea
in function space is the Leray (Helmholtz) projection onto divergence-free velocity fields.
A is 3×3 with detA=2. Find det(2A),det(A−1) and det(A⊤A).Answerdet(2A)=23⋅2=16;det(A−1)=1/2;det(A⊤A)=detA⊤detA=4.
A 3×3 matrix has eigenvalues 2,−1,3. Is it invertible? Give detA and trA.AnswerYes: 0 is not an eigenvalue. detA=2⋅(−1)⋅3=−6,trA=2−1+3=4.
Project b=(2,1,0) onto the line through a=(1,1,1). Give p and e, and check.Answera⊤b=3,a⊤a=3, so p=(1,1,1) and e=(1,0,−1);a⊤e=0 ✓.
Why does a 3×2 matrix A with independent columns have a left inverse but no right inverse?AnswerLeft: (A⊤A)−1A⊤A=I2, and A⊤A is invertible because the columns are independent. Right: AB=I3 would need rank 3, but rank(AB)≤rankA=2.
P is the orthogonal projector onto a k-dimensional subspace of Rm. Give its
eigenvalues, trace and determinant.AnswerEigenvalue 1 (k times, on the subspace) and 0 (m−k times, on its orthogonal complement). trP=k.detP=0 unless k=m, where P=I and detP=1.
Compute det210421231 by elimination.AnswerRow 2 − ½·row 1 gives (0,0,2). The second pivot position is now 0, so exchange rows 2 and 3 (sign flips): rows (2,4,2),(0,1,1),(0,0,2). Pivots 2,1,2, one exchange: det=−(2⋅1⋅2)=−4.
Recall cardsAnswer in your head first, then reveal. Add the cards to your review deck to see them again just before you would forget.
Give three conditions equivalent to "the square matrix A is invertible".
detA=0;N(A)={0};rankA=n (also: 0 is not an eigenvalue, the columns form a basis).
What does detA mean geometrically, and what does its sign mean?
∣detA∣ is the factor by which A multiplies volumes; the sign is − when A reverses orientation (makes a mirror image).
How do you get detA from elimination?
detA=(−1)#row exchanges× (product of the pivots). Adding multiples of rows does not change it.
State the product rule for determinants, and one consequence.
det(AB)=detAdetB. For example det(A−1)=1/detA and det(M−1AM)=detA.
How are detA and trA related to the eigenvalues?
detA=λ1⋯λn and trA=λ1+⋯+λn (with multiplicities, complex ones included).
Write the angle between nonzero u and v with the dot product.
cosθ=∥u∥∥v∥u⊤v; Cauchy–Schwarz (∣u⊤v∣≤∥u∥∥v∥) keeps it in [−1,1].
Give the projection of b onto the line through a.
p=a⊤aa⊤ba, with P=a⊤aaa⊤.
What equation defines x^ in the projection onto C(A), and why?
A⊤(b−Ax^)=0, the normal equations: the error must be perpendicular to every column of A.
What do P2=P and P⊤=P say about a projection matrix?
Projecting twice changes nothing, and the projection is orthogonal (the error is perpendicular to the subspace).
For square A,B with BA=I, why is AB=I?
BA=I gives N(A)={0}, so A (square) has full rank and some C has AC=I; then B=B(AC)=(BA)C=C.
"Why not compute A−1 to solve Ax=b?" — Three times the flops of LU, and not backward
stable: the residual can be up to about κ(A) times worse.
"What does detA=0 mean? Is a tiny det a problem?" — The columns span a flat box: A is
singular. A tiny det alone means little, because it depends on scale; look at κ(A).
"Derive the projection matrix." — The error is orthogonal to C(A):A⊤(b−Ax^)=0;A⊤A is invertible for independent columns.
"How do you compute logdet of a covariance? In a normalizing flow?" — Cholesky,
2∑ilogLii; flows use triangular Jacobians.
The notebook for this lesson runs in Colab. It has five exercises, each with a check cell
and a folded solution:
Compute the signed area of a polygon (shoelace formula) and check that a matrix multiplies it by
detA, sign included; then test the product rule on random matrices.
Write project_onto_line: return x^,p and the rank-1 matrix P=aa⊤/a⊤a.
Write projector(A) with np.linalg.solve (no inverse), and check P2=P,P⊤=P and
trP=rankA on section 4(c).
Solve or invert? Measure the relative residuals of solve and inv(H) @ b on Hilbert matrices
of growing size.
Enforce a conservation law Cx=0 by projecting a prediction onto N(C), and check that the
result is the closest point that satisfies the law.
Open on YouTube · the player loads from youtube-nocookie.com when you press playOpen on YouTube · the player loads from youtube-nocookie.com when you press playOpen on YouTube · the player loads from youtube-nocookie.com when you press playOpen on YouTube · the player loads from youtube-nocookie.com when you press play
Boyd and Vandenberghe, Introduction to Applied Linear Algebra (VMLS),
free PDF: §3.1 and §3.4 (norm, angle), §11.1–11.3 (left and right inverses, inverse, solving
linear equations).
Code along in Colab
Runs in your browser with nothing to install. The notebook repeats the key demos and has exercises with checks; solutions are inside, folded.