linear_algebra#

  • Series: lecture-python.myst

  • File: lectures/linear_algebra.md

  • Audit date: 2026-08-26

  • Corpus snapshot: e25fdf2345

  • Categories audited: writing, math, code, figures, references, links, admonitions (JAX out of scope)

  • Overall score: 6.9 / 10

  • Priority: HIGH

Score breakdown#

Category

Score

One-line note

Writing

3/10

qe-writing-006 ×18; qe-writing-003 ×5; qe-writing-001 ×4, +5 more.

Math

4.5/10

qe-math-002 ×114; qe-math-009 ×4.

Code

7.5/10

qe-code-001 ×5.

JAX

out of scope

JAX rules target lecture-jax.

Figures

5.5/10

qe-fig-005 ×5; qe-fig-007 ×4; qe-fig-001 ×5, +1 more.

References

10/10

no mechanical violations detected.

Links

7.5/10

qe-link-002 ×6.

Admonitions

10/10

no mechanical violations detected.

Issues#

Critical#

None found.

High severity#

  • [qe-code-001] (reviewer) — Follow PEP8 unless closer to mathematical notation. Count: 5. Lines: 115, 188, 310, 686, 949. Example: the same misindentation appears five times: at 115-119, 183-187, 196-200, 965-969 and 974-978 the arrowprops=dict(...) continuation lines are aligned with ax.annotate(‘s first argument rather than with dict(‘s opening bracket, so shrink, alpha and width read as arguments of annotate (E128). 188 and 201 pass the font size as a string, fontsize='16', where 326, 710, 717, 720 and 726 pass it as an int in the same file. The name x is rebound five times inside the span cell (300-344) as a zero array (310), a two-element tuple (330) and a mesh coordinate, and z three times (309, 324, 332), in a lecture whose subject is what \(x\) and \(z\) denote as vectors. 318 and 686 both define a module-level def f(x, ...), the second shadowing the first for a different purpose (a plane, then a cosine). And 949 rebinds evecs from the 2-d array returned by eig to a tuple of its two columns, so the name means one thing in the figure cell and another in the cell at 1021-1026 that prints it - which is also what 1029’s note (“the columns of evecs are the eigenvectors”) is having to explain.

  • [qe-fig-001] — Do not set figure size unless necessary. Count: 5. Lines: 104, 174, 298, 695, 951. Example: figsize=.

  • [qe-fig-005] — Descriptive figure names for cross-referencing. Count: 5. Lines: 103, 170, 294, 682, 941. Example: code-cell figure without mystnb figure metadata.

  • [qe-link-002] — Use doc links for cross-series references. Count: 6. Lines: 68, 206, 610, 616, 634, 1379. Example: raw link to python-programming.quantecon.org.

  • [qe-math-002] — Use \top for transpose notation. Count: 114. Lines: 231, 239, 476, 478, 847, 913, 1131, 1132, 1154, 1155, …. Example: apostrophe transpose x'.

  • [qe-writing-003] (reviewer) — Maintain logical flow. Count: 5. Lines: 470, 1056, 1196, 1277, 1341. Example: two sign errors sit in the displayed solution. 1277 writes \(\frac{\partial L}{\partial u} = -(Q+Q')u - B'\lambda = -2Qu + B'\lambda = 0\), in which the middle and right-hand expressions disagree in the sign of the \(B'\lambda\) term; from the Lagrangian at 1251 the correct derivative is \(-2Qu + B'\lambda\), so the first expression is the wrong one - and the substitution at 1283 quietly uses the correct version. 1341 writes \(-2u'B'PAx = -2x'S'B'PAx\), but \(u = -Sx\) gives \(u' = -x'S'\), so the middle expression should be \(+2x'S'B'PAx\); the next line then has \(+2\), so again the reader sees a sign appear from nowhere. 1196 asks a question in parentheses - “(What must the dimensions of \(y\) and \(u\) be to make this a well-posed problem?)” - that the solution never answers: its primitive list at 1241-1246 restates \(P\), \(Q\), \(A\) and \(B\) and omits \(y\) and \(u\) entirely. 1056-1064 is a section titled “Series Expansions” whose whole content is that “A generalization of this idea exists in the matrix setting”; the generalization arrives three subsections later at {eq}`la_neumann` (1100) with no sentence linking it back to the geometric series at 1062. And 470 asserts “For obvious reasons, the matrix \(A\) is also called a vector if either \(n=1\) or \(k=1\)” without giving the reasons.

  • [qe-writing-006] — Capitalize lecture titles properly. Count: 18. Lines: 124, 220, 391, 426, 486, 637, 656, 755, 778, 814, …. Example: H3 Title Case: ‘Vector Operations’ (Operations).

  • [qe-writing-008] — Remove excessive whitespace between words. Count: 5. Lines: 88, 352, 1006, 1146, 1217. Example: 2 spaces.

Medium severity#

  • [qe-fig-007] — Keep figure box and spines. Count: 4. Lines: 109, 179, 702, 956. Example: spine removal.

  • [qe-fig-008] — Use lw=2 for line charts. Count: 2. Lines: 716, 725. Example: plot() without lw=.

  • [qe-math-009] (reviewer) — Choose simplicity in mathematical notation. Count: 4. Lines: 231, 476, 1148, 1321. Example: 476 is the most consequential line in the file: “The matrix formed by replacing \(a_{ij}\) by \(a_{ji}\) … is called the transpose of \(A\) and denoted \(A'\) or \(A^{\top}\)”. It offers both notations, and the lecture then uses the apostrophe 114 times and ^{\top} never again - including in the defining equation of the inner product at 231, \(x' y := \sum_i x_i y_i\), and throughout the quadratic forms at 1131-1158 and the whole exercise solution at 1230-1373. This is the lecture the rest of the corpus learns its notation from, so licensing the prime here is where the corpus-wide qe-math-002 count comes from. 1148-1150 also overloads \(y\): the differentiation list declares “\(B\) be an \(m \times n\) matrix and \(y\) be an \(m \times 1\) vector”, while \(y\) is the \(n \times 1\) left-hand side of \(y = Ax\) everywhere else in the lecture (38-39, 669, 761, 820) and again in the exercise at 1187. The Lagrangian is \(\mathcal L\) in the exercise (1201, 1206) and plain \(L\) in the solution (1251, 1260, 1277, 1297) for the same object. And 1321 sets an English word in math mode, \,\,\,\, with \,\,\,\,, padded with four thin spaces on each side.

  • [qe-writing-001] — Use one sentence per paragraph. Count: 4. Lines: 1146, 1217, 1378, 1381. Example: 2 sentences in one paragraph.

  • [qe-writing-002] (reviewer) — Keep writing clear, concise, and valuable. Count: 4. Lines: 255, 822, 909, 1227. Example: 822-839 takes nine one-sentence paragraphs to establish that a \(k\)-dimensional plane is unlikely to contain an arbitrary point of \(\mathbb R^n\). 1227-1252 restates the exercise’s entire setup - objective, constraint, four primitives, Lagrangian - which 1178-1204 has just given, changing only \(\mathcal L\) to \(L\); and 1305-1306 closes a step with a circular clause, “which follows from the definition of the first-order conditions for Lagrangian equation”. 909 is ungrammatical (“we can solve for \(x = A^{-1} y\) by either via inv(A) @ y, or using solve(A, y)”), and 1166 likewise (“Chapters 2 and 3 of the [Econometric Theory] contains a discussion”). 255 drops a 32-word paragraph on fused multiply-add and BLAS between two one-line code cells, where the point being made is only that @ is preferred.

  • [qe-writing-004] — Avoid unnecessary capitalization in narrative text. Count: 1. Lines: 1166. Example: mid-sentence ‘Theory’.

  • [qe-writing-005] (reviewer) — Use bold for definitions, italic for emphasis. Count: 3. Lines: 1254, 1271, 1308. Example: this is the batch’s most careful lecture on this rule and the deviation is confined to one place: **Step 1.**, **Step 2.** and **Step 3.** at 1254, 1271 and 1308 use bold as a heading inside the solution, where ##### headings or an enumerated list would carry the structure. 1166 also sets a book title as a link label rather than in italic. Everything else is right - about thirty definitions are bolded (88, 228, 234, 236, 276, 285, 287, 352, 402-403, 472, 474, 476, 478, 480, 482, 484, 644, 776, 791, 803, 807, 932-933, 1037, 1079-1080, 1082, 1131-1132) and italic is reserved for the three real emphases, multiplying (533), only if (654) and columns (1029).

  • [qe-writing-007] (reviewer) — Use visual elements to enhance understanding. Count: 4. Lines: 342, 951, 1074, 1094. Example: all five figures sit in the first 990 lines; the 330 lines from 1051 to the end - Series Expansions, Matrix Norms, Neumann’s Theorem, Spectral Radius, Positive Definite Matrices, Differentiating Forms, and the exercise - contain no figure and no code cell at all. Three of those want one badly: 1074-1082 defines the spectral norm as \(\max_{\|x\|=1}\|Ax\|\) and says a contractive \(S\) “pulls all vectors towards the origin”, which is the unit circle and its image - the same arrows-and-images construction the eigenvector cell at 941-986 already draws; 1109-1120 states Gelfand’s formula \(\rho(A) = \lim_k \|A^k\|^{1/k}\) with no numerical check, though eig is imported at 80 and plotting \(\|A^k\|^{1/k}\) against \(\max_i|\lambda_i|\) for \(k = 1..20\) is three lines; and 1127-1138 defines positive definiteness with no picture of \(x'Ax\) on the unit circle. The eigenvector figure itself (941-986) uses \(A = [[1,2],[2,1]]\), whose eigenvalues are \(3\) and \(-1\), so one red image arrow points the opposite way to its blue eigenvector - and 937-939 says only “the image \(Av\) of each \(v\) is just a scaled version of the original”, with no annotation of which arrow is which or what the two eigenvalues are. 342 uses cmap=cm.jet for the span plane, the one colormap most strongly advised against, and all five figures override figsize (104, 174, 298, 695, 951) and strip two spines each (106-109, 176-179, 699-702, 953-956).

Low severity#

None found.

Strengths#

  • About thirty terms are defined, every one in bold and every one in its own paragraph - vector (88), inner product (228), orthogonal (234), norm (236), span (287), linearly dependent/independent (402-403), full column rank (776), inverse matrix (791), determinant (803), nonsingular (807), eigenvalue/eigenvector (932-933), spectral norm (1080), contractive (1082), positive definite (1131) - with italic kept for the three genuine emphases at 533, 654 and 1029. This is the cleanest execution of the bold/italic rule in the batch.

  • The four questions posed at 57-62 organise the entire lecture and are answered structurally rather than in a list: the non-linear counterexample figure at 682-732 shows that existence and uniqueness both fail in general, 736-743 reduces \(Ax\) to a linear combination of the columns of \(A\), 745 identifies the range of \(f\) with the column span, and then the three cases \(n=k\) (755-812), \(n>k\) (814-847) and \(n<k\) (849-877) each return to the same questions with a different answer.

  • Cross-references carry the argument instead of decorating it: {ref}the figure <la_3dvec>`` at 407 reuses the 3-d span plane to explain linear dependence and again at 831 to explain why existence fails when \(n>k\), and 749 and 753 close the existence and uniqueness halves of the square-matrix case by pointing back to results proved 350 lines earlier at la_li and la_unique_reps.

  • Every computational claim comes with the way to check it and a named reason for the recommendation: three ways to compute a norm (258-266), two for the inner product with @ “preferred” and the BLAS justification given (252-255), and inv(A) @ y against solve(A, y) with “LU decomposition … numerically more stable, and hence should almost always be preferred” (909-911).

  • The eigenvalue characterisation is derived from the definition in five one-sentence steps - \(Av = \lambda v\), then \((A - \lambda I)v = 0\), then linear dependence of the columns, then a zero determinant, then a degree-\(n\) polynomial with \(n\) complex roots (989-1002) - and 1004-1011 then gives the four standard facts with the invertibility corollary attached to the first.

  • The two footnotes hold proofs that would otherwise interrupt: 1381 shows in one line of algebra that \(\|S\| < 1\) pulls every point towards the origin, which is the claim 1082 makes in passing, and 1378 explains why the lecture works with ordinary arrays rather than NumPy’s matrix type.

  • The exercise at 1174-1221 is a real LQ control problem rather than a drill, it says what the machinery is for (“in economic contexts Lagrange multipliers often are shadow prices”, 1214), and its {note} at 1216-1217 gives the substitution route to the same answer for a reader who does not want the multipliers.