9.7 Linear algebra problem set, part a: elimination, LU, bases, rank, determinants, eigenvalues, QR
The sections before this one write code that factors matrices. Gaussian elimination and LU with partial pivoting builds LU, Orthogonality, Householder QR, and orthogonal initialization builds QR and an orthogonal initializer, and Eigenvalues, power iteration, and the spectral radius builds power iteration and the spectral radius that Vanilla RNN with manual BPTT and truncation in AI Engineering uses to diagnose exploding gradients. Comparing those factors with NumPy’s is only meaningful if you know what the factors are supposed to be and why they exist: why pivoting is needed, what rank and null space mean for a least-squares fit, why an eigenvalue above 1 makes a recurrent network blow up.
Concepts from other sections (15)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- Power iteration: repeated multiplication and normalization, converging to the dominant eigenvector. Read more: 9.4 Eigenvalues, power iteration, and the spectral radius
- Spectral radius: . Read more: 9.4 Eigenvalues, power iteration, and the spectral radius
- Null space / kernel: the vectors a matrix sends to zero, ; a nonzero null space means the map loses information. Read more: Chapter 9: Linear Algebra
- Eigenvector / eigenvalue: a non-zero and scalar with . Read more: 9.4 Eigenvalues, power iteration, and the spectral radius
- roofline: the bound on a loop’s speed from peak compute , memory bandwidth , and arithmetic intensity . Read more: 22.3 Cache-blocked, packed, batch-invariant matmul in C in AI Engineering
- Partial pivoting: swapping the row with the largest absolute entry (among rows and below) into the pivot position before eliminating. Read more: 9.2 Gaussian elimination and LU with partial pivoting
- Linear map: a function between vector spaces with ; once bases are chosen, every linear map is a matrix. Read more: Chapter 9: Linear Algebra
- Determinant: a single number for a square matrix: the factor by which scales signed volume. It is zero exactly when squashes space flat and so cannot be inverted, and . Read more: Chapter 9: Linear Algebra
- Unit lower triangular: lower triangular with ones on the diagonal. Read more: 9.2 Gaussian elimination and LU with partial pivoting
- Orthonormal: a set of unit-length vectors that are pairwise orthogonal. Read more: 9.3 Orthogonality, Householder QR, and orthogonal initialization
- rounding error: the error from floating-point rounding, about in a difference quotient. Read more: 7.1 Derivatives and Finite Differences
- Characteristic polynomial: , whose roots are the eigenvalues of . Read more: Chapter 9: Linear Algebra
- Orthogonal projection: , the closest point to on the line through . Read more: 9.6 Inner products, projections, cosine similarity, and top-k
- Sign rule: flipping signs so that , which makes the factorization unique. Read more: 9.3 Orthogonality, Householder QR, and orthogonal initialization
- Inner product: . Read more: 9.6 Inner products, projections, cosine similarity, and top-k
This problem set works those ideas by hand, on matrices small enough to check on paper. It is a pen-and-paper set with no code to write. It assumes the vectors, matrices, and matrix product of Vectors, matrices, row-major layout, and matmul and the overview in the chapter opening, and it fits best after the LU, QR, and power-iteration sections. Its sequel, the linear algebra problem set, part b, covers SVD, projections, and the roofline, and follows the SVD and inner-product sections.
Every problem is followed by a collapsed worked answer with the final result, the derivation, and the common wrong answers and why they are wrong. There are 44 exact answers and 4 proofs (q10, q20, q28, q44); model proofs for those four are also in course/solutions/solve/S-M03a/. Try each problem before opening its answer.
Learning objectives
- Carry out elimination by hand, read off and , and apply partial pivoting.
- Test vectors for independence, find bases of column and null spaces, and use rank-nullity.
- Build the matrix of a linear map from the images of the basis vectors and compose maps in the right order.
- Compute determinants and eigenvalues of small matrices and connect them to volume, singularity, and repeated multiplication.
- Project onto a line, orthonormalize with Gram-Schmidt, and solve a small least-squares problem.
The ideas in brief
Section titled “The ideas in brief”These are the facts the problems draw on, gathered in one place. The notation is standard:
| Symbol | Meaning | Type / shape |
|---|---|---|
| a matrix with rows and columns | matrix | |
| the unknown and the right-hand side of | vectors | |
| permutation, unit lower triangular, upper triangular: | ||
| all linear combinations | subspace | |
| the number of vectors in any basis of | integer | |
| the dimension of the column space (equal to that of the row space) | integer | |
| the null space ; its dimension is the nullity | subspace | |
| the determinant of a square matrix | real | |
| an eigenvalue and an eigenvector: , | scalar, vector | |
| the spectral radius, $\max | \lambda | |
| orthonormal columns and upper triangular: | matrices |
Elimination and LU
Section titled “Elimination and LU”Gaussian elimination subtracts multiples of a pivot row from the rows below it until the matrix is upper triangular, . Recording each multiplier (the amount of row subtracted from row ) in a unit lower triangular gives , so solving becomes two triangular solves. If a pivot is 0 the rows must be exchanged, and if it is merely small, dividing by it amplifies rounding errors; partial pivoting swaps the row with the largest in the current column into the pivot position, giving with every . The reduced row echelon form continues until each pivot is 1 and the only nonzero entry in its column. A system has no solution (inconsistent), exactly one, or infinitely many (a free variable).
Span, independence, basis, dimension
Section titled “Span, independence, basis, dimension”Vectors are linearly independent when forces every . A basis of a subspace is an independent spanning set, and every basis has the same size, the dimension: a basis is a minimal spanning set, and any vectors in are dependent. The pivot columns of are a basis of its column space; the special solutions (one per free variable) are a basis of its null space. Coordinates in a basis are the unique coefficients with : solve a linear system.
Linear maps and rank-nullity
Section titled “Linear maps and rank-nullity”A map is linear when and ; then where column of is . Composition is multiplication: has matrix (apply first, so it is on the right). For with columns, rank-nullity says : every column either adds a direction to the image or a direction to the null space.
Determinants
Section titled “Determinants”The determinant is the signed volume scale factor of : is the area of the parallelogram spanned by and . It is multiplicative, , so ; it scales as for ; a triangular matrix’s determinant is the product of its diagonal; and exactly when is singular.
Eigenvalues and eigenvectors
Section titled “Eigenvalues and eigenvectors”is an eigenvalue when is singular, that is, a root of the characteristic polynomial ; the product of the eigenvalues is and their sum is the trace. A real matrix may have complex eigenvalues (a rotation moves every real vector). If is an eigenvector, , so the largest , the spectral radius , decides whether repeated application grows () or shrinks (). Power iteration repeats ; the component along the second eigenvector shrinks by per step.
Orthogonality and QR
Section titled “Orthogonality and QR”The projection of onto the line through is . Gram-Schmidt subtracts from each column its projections onto the previous orthonormal vectors and normalizes the rest, giving ; requiring a positive diagonal of makes the factorization unique. Least squares minimizes ; its solution satisfies the normal equations , which QR solves stably as , as in SVD, Eckart-Young low rank, and least squares.
Two examples worked by hand
Section titled “Two examples worked by hand”Before the set itself, here are two siblings of q6, q7, and q36. They are not problems of the set, but they show the level of detail the answers use.
LU with partial pivoting. . The largest entry in column 1 is 6, in row 2, so swap: , . The multiplier is , and row 2 becomes . So , . Check: .
Eigenvalues and an eigenvector. is triangular, so and the eigenvalues are 3 and 2. For : gives , or any nonzero multiple such as . The product of the eigenvalues is .
How the answers are graded
Section titled “How the answers are graded”The problems are grouped by topic, in the order of the summary above. Answers are exact (, not 0.7071). A vector is one column; a basis answer is correct if it is any basis of the right space; an eigenvector is correct up to a nonzero scalar. The tag after each problem says what kind of answer is expected.
Gaussian elimination and LU
Section titled “Gaussian elimination and LU”q1. Solve , . Give . [vector]
Answer
. Subtract 3 times the first equation from the second: , so , and back substitution gives . Check: , . Writing swaps the unknowns.
q2. Solve , , . Give . [vector]
Answer
. Eliminate : row 2 minus 2 row 1 gives ; row 3 minus row 1 gives . From the second, ; substituting, , so , , . Check all three: , , . reverses the order.
q3. Give the reduced row echelon form of . [matrix]
Answer
. Row 2 minus 2 row 1 gives ; then row 1 minus 3 row 2 clears the entry above that pivot. Stopping at gives an echelon form, not the reduced one: the reduced form needs zeros above every pivot.
q4. with unit lower triangular and upper triangular, no row exchanges. Give . [matrix]
Answer
. The multiplier is (row 2 minus 2 row 1), and stores it as is. The lu of Gaussian elimination and LU with partial pivoting would swap rows here (4 is the larger pivot candidate); without row exchanges, as asked, these are the factors. A common mistake is , the reciprocal, which gives .
q5. Give the of q4. [matrix]
Answer
. Row 2 becomes . Check: . Writing in the corner forgets to subtract row 1 from the second column.
q6. Factor as with partial pivoting (swap the row with the largest pivot candidate to the top). Give . [matrix]
Answer
. The pivot candidates in column 1 are 1 and 3; the larger is 3, so swap (, ). The multiplier is , at most 1 in size, which is the point of partial pivoting. Without pivoting the multiplier would be 3.
q7. Give the of q6. [matrix]
Answer
. Row 2 of becomes . Without pivoting one gets , a valid but not the pivoted factorization asked for.
q8. How many solutions has the system , ? [number]
Answer
. Subtracting the equations gives : the two lines and are parallel and distinct, so the system is inconsistent.
q9. Give the set of for which , has infinitely many solutions. [set]
Answer
. The determinant is nonzero for , giving exactly one solution. At both equations are : infinitely many solutions. At they are and , whose sum is : no solution. A common mistake is , which treats every singular case as underdetermined.
q10. Prove that if the square matrix is invertible, then has exactly one solution for every . [proof]
Answer
Claim. If the matrix is invertible, then for every the system has exactly one solution.
Proof. Let satisfy . Existence: put . Then by associativity. Uniqueness: if and , then , and multiplying on the left by gives . So for every there is exactly one solution, .
A proof needs both halves (existence and uniqueness) and should use only the definition of the inverse and associativity. Model proof also in q10.md.
Span, linear independence, basis, dimension
Section titled “Span, linear independence, basis, dimension”q11. Is in the span of and ? [bool]
Answer
Yes. . Matching forces , , and then holds.
q12. Are and linearly independent? [bool]
Answer
No. , so is a nontrivial combination.
q13. Give the dimension of the span of , , . [number]
Answer
. , so the third vector adds nothing, and the first two are independent. Answering 3 counts vectors rather than independent directions.
q14. Give a basis of the column space of . [basis]
Answer
. The second column is twice the first, so the column space is the line through . Listing both columns is wrong because a basis must be independent.
q15. Give a basis of the null space of (vectors in ). [basis]
Answer
(any basis of the plane is correct). The pivot is ; and are free. Setting and gives the two special solutions. Common mistakes: , which spans the row space (orthogonal to the null space), and giving only one vector when the nullity is .
q16. Give the coordinates of in the basis , . [vector]
Answer
. Solve : , , so , . Check: . swaps the coordinates.
q17. Give the dimension of the space of symmetric real matrices. [number]
Answer
. A symmetric matrix is fixed by three free numbers, and the three matrices with a single 1 in position , , or the pair form a basis. Answering 4 counts all matrices.
q18. Give the set of for which and are linearly dependent. [set]
Answer
. Two vectors in are dependent exactly when . Forgetting the negative root is the common mistake: and are also parallel.
q19. Give the dimension of the null space of . [number]
Answer
. Row 2 is twice row 1, so the rank is 1, and rank-nullity gives . Answering 1 reports the rank.
q20. Prove that any vectors in are linearly dependent. [proof]
Answer
Claim. Any vectors in are linearly dependent.
Proof. Let be the matrix with columns . The vectors are dependent exactly when for some , since . Reduce to echelon form; row operations do not change the solutions of . Each pivot occupies its own row and there are only rows, so at most of the columns have a pivot: some is a free variable. Set , every other free variable to 0, and solve for the pivot variables by back substitution. This gives with , so , and the vectors are dependent.
The key steps are translating dependence into , counting pivots against columns, and building an explicit nonzero solution from the free variable. Model proof also in q20.md.
Linear maps and rank-nullity
Section titled “Linear maps and rank-nullity”q21. Give the matrix of the rotation of by counterclockwise. [matrix]
Answer
. Column is the image of : and . rotate_pairs in Trigonometry, rotations, complex numbers, and Euler’s formula and RoPE in AI Engineering apply this matrix to pairs of coordinates. The transpose rotates clockwise.
q22. Give the matrix of from to . [matrix]
Answer
. The columns are and , giving a matrix for a map from to . Writing the images as rows gives the transpose, which does not even have the right shape.
q23. Give the rank of . [number]
Answer
. Row 3 minus row 2 equals row 2 minus row 1 (both ), so the rows are dependent; rows 1 and 2 are not parallel. Elimination leaves two pivots. (q31 changes the last entry to 10, which makes the matrix invertible.)
q24. Give the nullity (dimension of the null space) of the matrix of q23. [number]
Answer
. Rank-nullity: . The null space is spanned by : , , .
q25. A matrix has rank 4. Give the dimension of its null space. [number]
Answer
. The null space lives in (the number of columns), so its dimension is . Answering 1 computes , subtracting from the number of rows.
q26. Is , from to , a linear map? [bool]
Answer
No. A linear map sends 0 to 0, but . (Also .) It is an affine map.
q27. and . Give the matrix of (first , then ). [matrix]
Answer
. . As matrices, : the map applied first is on the right. Multiplying in the order of application gives , which sends to .
q28. Prove that the null space of an matrix is a subspace of . [proof]
Answer
Claim. For an matrix , is a subspace of .
Proof. Matrix multiplication is linear: and . Zero: , so . Addition: if and , then . Scaling: if , then . So is a nonempty subset of closed under addition and scalar multiplication: a subspace.
All three conditions are needed, and linearity of is the reason each holds. Model proof also in q28.md.
Determinants
Section titled “Determinants”q29. . [number]
Answer
. . Answering 15 adds the products instead of subtracting.
q30. . [number]
Answer
. The matrix is upper triangular, so the determinant is the product of the diagonal, . Answering 11 gives the trace.
q31. . [number]
Answer
. Expand along row 1: . Common mistakes: 3 (a sign slip in the cofactor pattern ) and 0, which is the determinant of the matrix with a 9 in the corner (q23’s).
q32. is with . Give . [number]
Answer
. Scaling every entry by 2 scales each of the 3 rows by 2, and the determinant is linear in each row: . Answering 10 scales only once.
q33. . Give . [number]
Answer
. . Answering confuses the inverse with the negative.
q34. Give the area of the parallelogram spanned by and . [number]
Answer
. The area is . Answering 7 adds the products.
Eigenvalues and eigenvectors
Section titled “Eigenvalues and eigenvectors”q35. Give the eigenvalues of . [set]
Answer
. A diagonal matrix has its diagonal entries as eigenvalues, with eigenvectors and . Answering adds them (that is the trace).
q36. Give the eigenvalues of . [set]
Answer
. . Check: the sum is the trace and the product is the determinant. Reading off the diagonal works only for triangular matrices.
q37. Give an eigenvector of the matrix of q36 for its largest eigenvalue. [vector]
Answer
(or any nonzero multiple). gives . Check: . is the eigenvector of the other eigenvalue, 1.
q38. Give the characteristic polynomial of . [expr in t]
Answer
. . Check: the constant term is and the coefficient is . Common mistakes: (the off-diagonal product dropped) and (the sign of the trace term).
q39. Give the (complex) eigenvalues of the rotation . [set]
Answer
. . No real vector is mapped onto its own line by a rotation, so the eigenvalues cannot be real. are the eigenvalues of a reflection.
q40. Give the product of the eigenvalues of . [number]
Answer
. The product of the eigenvalues is (the eigenvalues are 5 and 2). Answering 7 gives their sum, the trace.
q41. With from q36, give . [vector]
Answer
. is the eigenvector for (q37), so and . Answering multiplies by instead of raising to the power.
q42. Give the spectral radius (largest ) of . [number]
Answer
. For the eigenvalues are (eigenvectors ): here . A spectral radius below 1 makes repeated multiplication shrink, which is the vanishing-gradient story of Vanilla RNN with manual BPTT and truncation. Common mistakes: (the diagonal entry) and (the smaller eigenvalue).
q43. Power iteration on the matrix of q36 from a generic start shrinks its error by the factor per step. Give that factor. [number]
Answer
. from q36: the component along is multiplied by 1 per step while the one along is multiplied by 3, so their ratio shrinks by a factor 3 each step. The power_iteration of Eigenvalues, power iteration, and the spectral radius converges at this rate. Answering 3 inverts the ratio.
q44. Prove that eigenvectors of with eigenvalues are linearly independent. [proof]
Answer
Claim. If , , , and , then and are linearly independent.
Proof. Suppose (1). Apply : (2). Subtract times (1) from (2): . Since and , . Then (1) reads , and gives . So only the trivial combination is 0.
The essential move is getting a second equation by applying and eliminating one vector; both hypotheses ( and ) must be used. Model proof also in q44.md.
Orthogonality and QR
Section titled “Orthogonality and QR”q45. Give the orthogonal projection of onto the line spanned by . [vector]
Answer
. . The residual is orthogonal to , as it must be. This is the inner-product step of Inner products, projections, cosine similarity, and top-k and of Gram-Schmidt. Answering forgets to divide by .
q46. . Gram-Schmidt on its columns gives with having orthonormal columns and upper triangular with a positive diagonal. Give . [matrix]
Answer
. Normalize : . Then , and , with length , so . Common mistakes: leaving the second column unnormalized, and flipping the sign of , which makes negative and violates the uniqueness convention.
q47. Give the of q46. [matrix]
Answer
. : , , is the length of what was left of , . Check the second column: . Writing forgets that ‘s columns are normalized.
q48. Fit to the points , , by least squares. Give . [number]
Answer
. Minimize : the derivative is zero at . This is the normal equation for the one-column ; the lstsq of SVD, Eckart-Young low rank, and least squares solves it through QR. Common mistakes: , and 1, which fits only the first two points.
Common mistakes
Section titled “Common mistakes”The wrong answers discussed above fall into a handful of patterns. Each one has a symptom you can spot and a habit that prevents it:
| Mistake | Symptom | The habit that avoids it |
|---|---|---|
| Storing the reciprocal of the multiplier in | store itself (q4) | |
| Skipping the pivot search | multipliers larger than 1 and unstable factors; differs from NumPy’s | pick the largest as pivot before eliminating (q6, q7) |
| Calling an echelon form “reduced” | entries above the pivots left nonzero | clear the entries above each pivot too (q3) |
| Counting vectors instead of independent vectors | dimension and rank too large | check each vector against the span of the previous ones (q13, q14) |
| Confusing rank with nullity, or rows with columns in rank-nullity | the wrong null space dimension | subtract the rank from the number of columns (q19, q25) |
| Writing images of basis vectors as rows | the transpose of the map’s matrix | write as column (q22) |
| Multiplying maps in the order they are applied | instead of | put the map applied first on the right (q27) |
| volume scale off by | scale once per row: (q32) | |
| Reading eigenvalues off the diagonal of a non-triangular matrix | wrong spectral radius; an RNN diagnosed as stable when it is not | solve the characteristic polynomial (q36, q42) |
| Forgetting to divide by in a projection | projections scaled by | divide by (q45) |
Where this leads
Section titled “Where this leads”Each group of problems is the hand version of code in this chapter. q4 to q7 are the factors that lu and lu_solve compute in Gaussian elimination and LU with partial pivoting. The uniqueness convention of q46 and q47 is the sign rule of Orthogonality, Householder QR, and orthogonal initialization. The rate in q43 is the convergence rate of power_iteration and spectral_radius in Eigenvalues, power iteration, and the spectral radius, and q48 is least squares through QR in SVD, Eckart-Young low rank, and least squares. The linear algebra problem set, part b continues with inner products and projections, SVD and low rank, and FLOP and byte counts.
Further reading
Section titled “Further reading”- Strang, Introduction to Linear Algebra, ch. 2 to 6, and MIT 18.06 lectures 1 to 21.
- Hefferon, Linear Algebra (free), ch. 1 to 5.
Summary
Section titled “Summary”- Elimination is LU: the multipliers are , the result is , and partial pivoting keeps every multiplier at most 1 in size (q4 to q7).
- A basis is a minimal spanning set; its size, the dimension, is the same for every basis, and any vectors in are dependent (q13, q20).
- Rank plus nullity equals the number of columns: every column either adds a direction to the image or a direction to the null space (q23 to q25).
- The determinant measures how a matrix scales volume; it is the product of the eigenvalues and is 0 exactly when the matrix is singular (q31, q34, q40).
- Repeated multiplication by is governed by its eigenvalues: , power iteration converges at rate , and a spectral radius below 1 shrinks everything (q41 to q43).