For Sarang. Written to help you pass the exam, really understand the ideas, and blog about them.
How to use this guide
- Read the In one line and Plain-English parts first. They build the picture.
- Then work the Worked example with pen and paper before you read the steps.
- Before the exam, do the Exam traps sections and the cheat sheet at the end.
- Every number in this guide was checked in Python (numpy).
1. Course at a glance
Instructor: Dr. Ketan Rajawat (IIT Kanpur). References he recommends: Boyd & Vandenberghe, Introduction to Applied Linear Algebra (VMLS). Strang, Linear Algebra for Everyone. The slides follow Boyd & Vandenberghe very closely, so use that book when you need more explanation.
Evaluation scheme (stated on the Introduction slides)
| Component | Weight |
|---|---|
| Assignments (submitted) | 20% |
| Quiz | 15% |
| Attendance in discussion (live) sessions | 10% |
| End-semester exam (online) | 55% |
- Only the best (n − 1) of n assignments count, so you can drop one.
- If you miss the quiz and have valid documents, you get a make-up quiz.
- If you miss the end-sem exam, you get an incomplete/fail grade (the exact letter was lost in the PDF text).
- The instructor's advice: spend at least 1.5× the video length on each video. Work with pen and paper. Do not look up assignment solutions online or ask ChatGPT for them.
Week-by-week map (worked out from assignment and live-session dates)
| Week (approx.) | Lecture topics | Live session / assignment |
|---|---|---|
| 1 (to ~22 Sep) | Ch 0 Intro · Ch 1 Vectors · Ch 2 Vector operations · Ch 3 Vector spaces | Assignment 1 (practice, 22 Sep) |
| 2 | Ch 4 Matrices · Ch 5 Basic matrix operations · Ch 6 Matrix multiplication | Live 26 Sep (fields, subspaces, blocks, flops); Assignment 2 |
| 3 | Ch 7 Inner products · Ch 8 Norms | Live 03 Oct (matrix ops, interpretations); Live 04 Oct (A2 discussion); Assignment 3 |
| 4 | Ch 9 Linear functions · Ch 10 Linear systems & least squares | Live 10 Oct (norms, Cauchy-Schwarz); Live 11 Oct (A3 discussion); Assignment 4 |
| 5 | Ch 11 LU & QR · Ch 12 SVD | Assignment 5 (17 Oct). Live 17 Oct & 18 Oct: not covered, because no material is available yet |
| Coming next | "Spaces associated with a matrix" (fundamental subspaces), linear independence, bases, eigenvalues | Listed on the intro slide but not yet released |
The story of the course (one paragraph)
A vector is just a list of numbers, such as a pixel row, a word-count row or an embedding. Vector spaces are the "playgrounds" where you can add and scale those lists without falling out. A matrix is a machine that takes a vector in and sends a new vector out. Matrix multiplication chains those machines together. The inner product measures how much two vectors point the same way. Norms measure size. Together they give you angles, distances and projections. Then the payoff: every linear function is secretly a matrix. So "solve a system of equations" means "find the input that the machine sends to b". When there is no exact answer, least squares finds the closest one, and that is linear regression. To do it fast and stably, we factor matrices into simpler pieces. LU (two triangles) and QR (a rotation times a triangle) are the solvers. Finally, the SVD says that every matrix is "rotate, stretch, rotate". That one fact gives you rank, compression, PCA and low-rank approximation, the ideas behind embeddings and LoRA.
2. Topic sections
2.1 Vectors (Ch 1)
In one line: A vector is an ordered list of numbers, like a row in a table where each position means something specific.
Plain-English explanation
Think of a shipment record: [weight, volume, distance]. Order matters. [5, 2, 300] is not the same shipment as [300, 2, 5]. That is all a vector is: an ordered, finite list.
- Entries (also called elements or components): the numbers inside. The i-th entry of vector
ais writtena_i. - Dimension n: how many entries it has. We write
a ∈ R^n, which means "a is a list of n real numbers". - Column vs. row: by default every vector in this course is a column (stacked vertically). A row vector is its transpose.
- Scalars are single numbers. Bold lowercase letters are vectors, plain letters are scalars.
Special vectors you must know
| Name | Notation | What it is |
|---|---|---|
| Zero vector | 0_n |
all zeros; adding it changes nothing |
| All-ones vector | 1_n |
all ones; 1^T x adds up all the entries of x |
| Standard unit vectors | e_1, …, e_n |
e_i has a 1 in position i and 0 everywhere else |
- Block (stacked) vectors:
a = [b; c; d]just glues vectors end to end. If b ∈ R^2, c ∈ R^3 and d ∈ R^1, then a ∈ R^6. - Subvectors:
a_{r:s}is entries r through s. It has s − r + 1 entries, like Python'sa[r-1:s].
Geometric picture (3Blue1Brown style): In 2D, [x, y] is an arrow from the origin to the point (x, y).
- A location vector is an arrow from the origin.
- A displacement vector is an arrow from one point to another:
Δp = p_2 − p_1. - Same arrow, different meaning: a location is just "displacement from the origin".
Applications from the slides
- Colour: RGB is a 3-vector.
- Image: an 800×600 greyscale image is a vector of 480,000 pixel intensities. A colour image has 3 numbers per pixel.
- Word counts: with the dictionary
[apple, banana, orange], the text "I like apple and banana" becomes[1, 1, 0]. - One-hot coding: each category becomes a standard unit vector, e.g. Apple =
e_1, Banana =e_2.
Worked example
You move a delivery bike from p_1 = (1, 2) to p_2 = (4, 6). What is the displacement?
- Δp = p_2 − p_1 = (4 − 1, 6 − 2) = (3, 4).
- Distance travelled in a straight line: √(3² + 4²) = √25 = 5. This previews the norm.
How many numbers are needed for an 800×600 colour image?
- Pixels = 800 × 600 = 480,000.
- Three intensities (R, G, B) per pixel: 480,000 × 3 = 1,440,000.
Why it matters in ML/AI
- Every data point a model sees is a vector: a feature row, an image, a token embedding.
- One-hot vectors are what goes into an embedding lookup. Multiplying an embedding matrix E by
e_ijust picks out column i. - Bag-of-words vectors were the first document representations in NLP.
Exam traps
- Subvector length is s − r + 1, not s − r.
c_{5:14}has 10 entries. - You can only add vectors of the same size. Assignment 1 Q1 is a whole question of "is this expression even valid?"
- In
b = [0; a]with a ∈ R^10 and b ∈ R^15, the zero block must be size 5. But in[0; a; 0]you cannot tell how the 5 zeros split between the two blocks. The instructor tests exactly this kind of ambiguity. [a b](side by side) is a 10×2 matrix, not a 20-vector.[a; b](stacked) is the 20-vector.
Blog angle: "Everything is a vector: how your photo, your playlist and your shopping cart become lists of numbers."
- Images, text and categories all become vectors, but the order of entries carries the meaning.
- One-hot coding and why it is wasteful, which is why embeddings exist.
- Location vs. displacement: the same arrow with two meanings, and why ML cares (positions vs. deltas/gradients).
Source tag: Course slides (Ch 1) + Assignment 1. Textbook fill-in (Boyd & Vandenberghe Ch 1) for the geometric picture.
2.2 Vector operations & linear combinations (Ch 2)
In one line: You can add vectors and stretch them. Doing both at once, a "linear combination", is the single most important move in the whole course.
Plain-English explanation
- Addition works entry by entry:
(a + b)_i = a_i + b_i. Geometrically: walk along a, then along b (tip-to-tail). - Scaling multiplies every entry by a scalar α. Geometrically it stretches the arrow.
- If α > 0, the arrow keeps its direction.
- If α < 0, it flips.
- If α = 0, it collapses to the zero vector.
- Properties:
- Addition is commutative (
a + b = b + a) and associative. a + 0 = aanda + (−a) = 0.- Scaling distributes over addition:
α(a + b) = αa + αband(α + β)a = αa + βa.
Linear combination: α_1 a_1 + α_2 a_2 + … + α_m a_m. The α's are coefficients (weights) and the a's are the component vectors.
Key fact: every vector is a linear combination of the standard unit vectors.
- Example:
(3, −2, 4) = 3e_1 − 2e_2 + 4e_3. - So the entries of a vector are just the weights on e_1, e_2, ….
Displacement logic: if you take displacements x_1, x_2, …, x_k and end where you started, then x_1 + … + x_k = 0. The intermediate positions cancel like a telescoping sum. (This is Assignment 1 Q4, the robot vacuum.)
Cost (flops):
- A flop is one floating-point add, subtract, multiply or divide.
- Adding two n-vectors costs n flops. Scaling one costs n flops.
- Adding N vectors of length L costs (N − 1)·L flops. The order of adding does not change this.
- Memory to hold two n-vectors in 64-bit floats: 2n × 64 bits.
Worked example
a = (1, −2, 4), b = (2, 3, −1).
- a + b = (1 + 2, −2 + 3, 4 − 1) = (3, 1, 3).
- b − a = (2 − 1, 3 − (−2), −1 − 4) = (1, 5, −5).
- 2a − 3b = (2 − 6, −4 − 9, 8 + 3) = (−4, −13, 11).
Flops and storage (Assignment 1 Q3 style). You have 100 vectors, each of length 10^8, in 64-bit floats.
- Storage = 100 × 10^8 numbers × 8 bytes = 8 × 10^10 bytes = 80 GB.
- Flops to add them = (100 − 1) × 10^8 = 9.9 × 10^9.
- At 10^9 flops/s, the time is 9.9 × 10^9 / 10^9 = 9.9 seconds.
Why it matters in ML/AI
- A neuron computes a weighted sum, i.e. a linear combination of its inputs.
- Word-vector arithmetic ("king − man + woman ≈ queen") is literally vector addition and scaling.
- Flop counting is how you estimate GPU cost. It is the same mental model as sizing a Kafka cluster from messages per second.
Exam traps
- Forgetting the N − 1 in "add N vectors". Adding 2 vectors is 1 round of additions, not 2.
- Storage: 64 bits = 8 bytes. Mixing up bits and bytes is the classic mistake.
- Robot question: the answer is the zero vector
0, not the scalar 0.
Blog angle: "Linear combinations: the one idea behind neurons, recipes and word-vector arithmetic."
- Recipe analogy: ingredients are vectors and quantities are weights.
- Every vector is "weights on unit vectors", so coordinates are just recipes.
- Counting flops: back-of-envelope estimates for ML compute.
Source tag: Course slides (Ch 2) + Assignment 1 + Live 26 Sep (AI outline: telescoping sum, N−1 additions).
2.3 Fields, vector spaces & subspaces (Ch 3)
In one line: A vector space is a set that you cannot escape by adding or scaling. A subspace is a smaller such set inside a bigger one, and it must pass through the origin.
Plain-English explanation
- Field F: where your scalars come from. You need to be able to add, subtract, multiply and divide (except by 0) inside it. Examples: R (reals), C (complex), Q (rationals). The integers are not a field, because 1/2 is not an integer.
- Vector space V over F: a set where every linear combination (with scalars from F) stays inside. Check three things: 1. 0 ∈ V (contains the zero vector). 2. Closed under addition: u, v ∈ V ⇒ u + v ∈ V. 3. Closed under scaling: v ∈ V, α ∈ F ⇒ αv ∈ V.
- Subspace W ⊆ V: a subset that is itself a vector space, so it passes the same three checks.
Geometric picture:
- In R^3, the only subspaces are {0}, lines through the origin, planes through the origin, and R^3 itself.
- A line or plane that misses the origin is not a subspace. Scale any point by 0 and you land on the origin, which isn't in the set.
- A circle, a disc, a box such as [0, 1]^n, or the half-plane x_1 ≥ 0 are not subspaces. Scaling or adding takes you outside.
Software analogy: a subspace is like a type that is closed under its operations. If adding two Money objects could give you a String, the type would be broken. A subspace guarantees "add or scale anything in here and you stay in here".
The field matters. R^2 sits inside C^2, but it is not a subspace of C^2 over F = C. Take v = (1, 1) ∈ R^2 and the scalar i ∈ C. Then iv = (i, i) ∉ R^2. Over F = R, though, it is a subspace.
Canonical examples:
- R^n over R, C^n over C, and R^(m×n) (matrices) over R are vector spaces.
- The natural numbers N are not a vector space over R: no negatives, and 0.5·1 ∉ N.
Worked example (Assignment 1 Q5 style)
(a) W = {x ∈ R^3 | x_1 + 2x_2 + 3x_3 = 0}.
- Zero: 0 + 0 + 0 = 0 ✓.
- Addition: if x and y satisfy it, then (x_1 + y_1) + 2(x_2 + y_2) + 3(x_3 + y_3) = 0 + 0 = 0 ✓.
- Scaling: αx_1 + 2αx_2 + 3αx_3 = α·0 = 0 ✓.
- Subspace. Geometrically it is a plane through the origin with normal vector (1, 2, 3).
(b) W = {x | x_1 = 2x_2 = 3x_3}.
- Call the common value 6t. Then x = (6t, 3t, 2t) = t·(6, 3, 2).
- This is a line through the origin, so it is a subspace.
(c) W = {x ∈ R^2 | x_1 + x_2 = b}.
- Zero: 0 + 0 = b holds only if b = 0.
- Adding two members gives a sum of 2b, which is not b unless b = 0.
- So it is a subspace only when b = 0.
Why it matters in ML/AI
- The set of all outputs of a linear layer,
{Wx}, is a subspace (the column space). A rank-r layer can only output vectors in an r-dimensional subspace. That is the core idea behind LoRA. - PCA finds the best low-dimensional subspace to project data onto.
- Many "constraint sets" in optimisation (probability simplex, unit ball) are not subspaces. That is why they need projections or special solvers.
Exam traps
- Check the zero vector first. It is the fastest way to kill a non-subspace.
- To prove "not a subspace", one counterexample is enough. To prove "is a subspace", you must show the general case.
- Always ask "over which field?" The R^2-in-C^2 question was on Assignment 1 and was discussed in the 04 Oct live session.
x_1 = 2x_2 = 3x_3looks like two equations. Both are homogeneous (= 0 on the right after rearranging), so it is a subspace.
Blog angle: "Why your feature space must contain the origin: subspaces explained with lines, planes and LoRA."
- The 3-check test, plus "check zero first".
- Why an affine line (offset by b) fails, and how a bias term gets around it.
- The field matters: the R^2-inside-C^2 puzzle.
Source tag: Course slides (Ch 3) + Assignment 1 + Live 26 Sep & 04 Oct (AI outlines, cross-checked).
2.4 Matrices & basic matrix operations (Ch 4–5)
In one line: A matrix is a grid of numbers. Read it as a table, a stack of vectors, a graph, or (most importantly) a machine that transforms vectors.
Plain-English explanation
- An m × n matrix has m rows and n columns.
A_ijis the entry in row i, column j. Shapes: - Square: m = n.
- Tall: m > n.
- Wide: m < n.
- Columns view: A = [a_1 a_2 … a_n], each a_j ∈ R^m. Rows view: each row is a 1×n vector.
- Three interpretations from the slides:
1. Table: students × assignments, or regions × products.
2. Collection of vectors: e.g. N images, each a P-vector, as columns.
3. Relationship graph (adjacency matrix):
A_ij = 1if i → j (e.g. "i follows j on Instagram"). - Special matrices:
- Zero
0_{m×n}. - Identity
I_n(ones on the diagonal), which equals [e_1 … e_n]. - Diagonal
Diag(d)and block-diagonalblkdiag(B_1, B_2, …). - Upper triangular (zeros below the diagonal) and lower triangular (zeros above).
- Tensors: the same idea in more dimensions, e.g. a batch of colour images is an
N × H × W × 3tensor.
Storage & reshape. Memory is 1-D, so a matrix is stored as a long vector plus "shape" metadata.
- Fortran/MATLAB store column by column (column-major). C/C++/Python-numpy store row by row (row-major).
- Reshaping m×n to p×q needs mn = pq, and the result depends on the ordering.
- vec(A) stacks the columns.
Transpose flips the matrix across its diagonal: (A^T)_ij = A_ji.
(A^T)^T = Aand(A + B)^T = A^T + B^T.- Symmetric means A = A^T.
- For block matrices, you transpose each block and swap the block positions.
Addition and scaling work entry by entry, with the usual commutative and associative rules. The set of all m×n matrices is itself a vector space.
Matrix-vector product: the "machine" view (the most important idea here).
Av = v_1 a_1 + v_2 a_2 + … + v_n a_n
In words, Av is a linear combination of the columns of A, with weights taken from v.
3Blue1Brown picture:
- Column a_j is where e_j lands after the transformation.
- So Av says: "go v_1 steps along where e_1 landed, v_2 steps along where e_2 landed, …".
Row view (equivalent): entry i of Av is the dot product of row i of A with v.
Handy tricks from the slides:
Ae_iis column i of A.A^T e_jgives row j (as a column).A1sums each row, i.e. adds the columns together.A^T 1gives the column sums.- A difference matrix (−1, 1 on each row) gives forward differences v_2 − v_1, v_3 − v_2, …. A lower-triangular all-ones matrix gives running (cumulative) sums.
- Properties: A(v + w) = Av + Aw, (A + B)v = Av + Bv, and (αA)v = α(Av) = A(αv).
Flops (n × n):
- Transpose: 0 (it is just re-indexing).
- Scaling and addition: n².
- Matrix-vector: n(2n − 1) ≈ 2n². Each of the n outputs needs n multiplications and n − 1 additions.
Worked example (the slide's "neural network" example)
A = [[2, 4], [1, 3], [5, 2]] (3×2), v = (3, 1).
- Column view: Av = 3·(2, 1, 5) + 1·(4, 3, 2) = (6 + 4, 3 + 3, 15 + 2) = (10, 6, 17).
- Row view check: - Row 1: 2·3 + 4·1 = 10. - Row 2: 1·3 + 3·1 = 6. - Row 3: 5·3 + 2·1 = 17 ✓.
- Row sums A1 = (6, 4, 7). Column sums A^T 1 = (8, 9).
Block matrix (Assignment 2 Q1): A = [[I, B^T], [B, 0]] with B ∈ R^{3×5}.
- B^T is 5×3 and sits in the top-right, so the top-left I must be 5×5 (same number of rows as B^T).
- B is 3×5 and sits in the bottom-left, so the bottom-right 0 must be 3×3.
- A is (5 + 3) × (5 + 3) = 8×8, square.
- A^T = [[I^T, B^T], [(B^T)^T, 0^T]] = [[I, B^T], [B, 0]] = A, so A is symmetric.
- "I and 0 are the same size" is false in general (5×5 vs 3×3). "The 0 block is square" is true.
Why it matters in ML/AI
- A dense layer is
Wx + b. The live session pointed out that the bias can be absorbed: append a 1 to x and add b as an extra column of W. - Adjacency matrices are the input to graph neural networks and PageRank.
- Row-major vs column-major is why
numpy.reshapeandtorch.viewsometimes scramble your data. It is also why.contiguous()exists.
Exam traps
- Transposing a block matrix: swap the off-diagonal blocks AND transpose each block.
- Reshape results differ between MATLAB and Python because of the ordering.
- Matrix-vector flops are 2n² (more precisely n(2n − 1)), not n².
- Shape checking: an m×n matrix times an n-vector gives an m-vector. The inner dimensions must match.
Blog angle: "A matrix is a machine: the column picture that makes neural networks click."
- Columns are "where the unit vectors land".
- Av = mix the columns. That one sentence explains linear layers.
- Four costumes for a matrix: table, image stack, graph, transformation.
Source tag: Course slides (Ch 4, Ch 5) + Assignment 2 Q1 (official solution) + Live 03 Oct (AI outline: bias trick, storage metadata).
2.5 Matrix multiplication (Ch 6)
In one line: AB means "do B, then do A". It is composing two machines, so order matters.
Plain-English explanation
Definition: if A is m×n and B is n×p, then C = AB is m×p with
C_ij = Σ_k A_ik B_kj (row i of A dotted with column j of B).
Shape rule: (m×n)(n×p) → m×p. The inner sizes must match.
Four equivalent views (the instructor stresses all of them):
- Inner-product (entry) view: C_ij = (row i of A) · (column j of B).
- Column view: AB = [Ab_1 Ab_2 … Ab_p]. A acts on each column of B.
- Row view: each row of AB is (row i of A) times B.
- Outer-product view: AB = a_1 b_1^T + a_2 b_2^T + … + a_n b_n^T. This is a sum of rank-1 matrices, one per column of A paired with the matching row of B. The SVD builds on exactly this view.
Geometric picture: if B rotates and A stretches, then AB rotates first and then stretches. BA stretches first and then rotates, which is usually different. Hence:
- Not commutative: AB ≠ BA in general, even when both are defined.
- Still associative: (AB)C = A(BC).
- Distributive: A(B + C) = AB + AC.
- Transpose reverses order: (AB)^T = B^T A^T. Think "socks and shoes": you take them off in reverse order.
- Identity: AI = IA = A.
Special products:
- Inner product u^T v gives a scalar.
- Outer product u v^T gives a matrix with (uv^T)_ij = u_i v_j. Every outer product of non-zero vectors has rank 1. In general uv^T ≠ vu^T.
- Gram matrix G = A^T A has G_ij = a_i^T a_j, the dot products between columns. It is always symmetric.
- Trace: tr(A) = sum of the diagonal entries (square matrices only).
- It is linear.
- tr(AB) = tr(BA) even when AB ≠ BA.
- Cyclic: tr(ABC) = tr(BCA) = tr(CAB). But tr(ABC) ≠ tr(BAC) in general.
- Hadamard product A ⊙ B multiplies entry by entry (same shapes only). It is commutative.
Flops: an n×n by n×n product costs n²(2n − 1) ≈ 2n³.
Worked example
A = [[1, 2], [3, 4]], B = [[5, 6], [7, 8]].
- AB: - (1,1) = 1·5 + 2·7 = 19 - (1,2) = 1·6 + 2·8 = 22 - (2,1) = 3·5 + 4·7 = 43 - (2,2) = 3·6 + 4·8 = 50 - So AB = [[19, 22], [43, 50]].
- BA: - (1,1) = 5·1 + 6·3 = 23 - (1,2) = 5·2 + 6·4 = 34 - (2,1) = 7·1 + 8·3 = 31 - (2,2) = 7·2 + 8·4 = 46 - So BA = [[23, 34], [31, 46]] ≠ AB.
- Traces: tr(AB) = 19 + 50 = 69 and tr(BA) = 23 + 46 = 69. Equal, as the theorem promises.
- Hadamard: A ⊙ B = [[5, 12], [21, 32]].
Outer-product symmetry (Assignment 2 Q2): x = (1, 3), y = (2, 5).
- xy^T = [[2, 5], [6, 15]] but yx^T = [[2, 6], [5, 15]]. They are not equal.
- In general, entry (i, j) needs x_i y_j = x_j y_i, i.e. x_i / y_i = x_j / y_j for all i, j. So xy^T = yx^T iff y is a scalar multiple of x.
Matrix powers (Assignment 2 Q4): S = [[0,0,0,1],[1,0,0,0],[0,1,0,0],[0,0,1,0]], x = (1, 2, 3, 4).
- Sx = (x_4, x_1, x_2, x_3) = (4, 1, 2, 3). This is a downward circular shift.
- S²x = (3, 4, 1, 2), S³x = (2, 3, 4, 1), and S⁴x = x, so S⁴ = I.
- In general Sⁿ = S^((n−1) mod 4 + 1). For example S⁶x = S²x = (3, 4, 1, 2).
Nilpotent (Assignment 2 Q3): N = [[0, 1], [0, 0]] gives N² = 0 even though N ≠ 0. So does [[1, 1], [−1, −1]].
Why it matters in ML/AI
- A deep network is a chain of matrix products with nonlinearities between them. Without the nonlinearities, W_3 W_2 W_1 collapses into one matrix. That is why activations matter.
- Attention is Q K^T (all pairwise dot products, a Gram-like matrix), then softmax, then times V.
- Training cost estimates ("~6 × params × tokens flops") come straight from the 2n³-style counting.
- The trace trick tr(ABC) = tr(CAB) is used constantly in deriving gradients of matrix losses.
Exam traps
- Shape-check first. If AB is 3×5 and B is 4×5, then A must be 3×4.
- AB = 0 does not imply A = 0 or B = 0 (see nilpotent matrices).
- (AB)^T = B^T A^T, not A^T B^T. The same reversal applies to inverses.
- tr(AB) = tr(BA) holds even for non-square A (m×n) and B (n×m). Then AB is m×m and BA is n×n, yet the traces match.
- Permutation and shift matrices: test with a symbolic vector (x_1, x_2, x_3, x_4), as the instructor advises.
Blog angle: "Why AB ≠ BA: matrix multiplication as function composition (and why your neural net needs ReLU)."
- Four ways to see a matrix product, and when each one helps.
- Composition picture: rotate-then-stretch vs stretch-then-rotate.
- The outer-product view previews the SVD and low-rank adapters.
Source tag: Course slides (Ch 6) + Assignment 2 (official solutions) + Live 03 & 04 Oct (AI outlines, checked against the solutions).
2.6 Inner products (Ch 7)
In one line: The inner (dot) product multiplies matching entries and adds them up. It tells you how much two vectors point the same way.
Plain-English explanation
Definition: <u, v> = u^T v = u_1 v_1 + u_2 v_2 + … + u_n v_n. The result is a scalar.
Properties:
- Commutative:
<u, v> = <v, u>. <au, bv> = ab <u, v>.- Distributive:
<u + v, w> = <u, w> + <v, w>. - Together these make the inner product bilinear: linear in each argument separately.
The most-used expansion: <u + v, u + v> = <u, u> + 2<u, v> + <v, v>. This is just (a + b)² for vectors. Most proofs in Assignment 3 come down to this line.
Geometric meaning: <u, v> = ||u|| ||v|| cos θ. Equivalently, "length of the shadow of u on v, times the length of v".
- Large and positive: the vectors point the same way.
- Zero: they are perpendicular (orthogonal).
- Negative: they point in opposite directions.
Useful special cases:
<e_i, v> = v_ipicks out one entry.<1, v>= sum of the entries.<v, v>= sum of the squares = ||v||².- Co-occurrence: with indicator vectors of two sets,
<v_A, v_B>counts the common elements. - Polynomial evaluation: p(a) =
<coefficients, (a^(n−1), …, a, 1)>.
Matrix-vector, row view: (Ax)_i = <row i of A, x>.
Moving a matrix across: <y, Ax> = <A^T y, x>.
- Proof: y^T A x is a scalar, so it equals its own transpose: (y^T A x)^T = x^T A^T y.
- This "move A to the other side as A^T" trick is everywhere in backprop.
Block vectors: <[v_1; v_2], [w_1; w_2]> = <v_1, w_1> + <v_2, w_2>.
Matrix inner product: <A, B> = Σ_ij A_ij B_ij = tr(A^T B) = <vec(A), vec(B)>.
Cost: n multiplications + (n − 1) additions = 2n − 1 flops.
Worked example
u = (1, 2, 3), v = (4, 5, 6).
<u, v>= 1·4 + 2·5 + 3·6 = 4 + 10 + 18 = 32.- ||u|| = √14 ≈ 3.742 and ||v|| = √77 ≈ 8.775.
- cos θ = 32 / (√14·√77) ≈ 0.9746, so θ ≈ 12.9°. The vectors are very similar in direction.
Orthogonal pair: (3, 1)·(−1, 3) = −3 + 3 = 0, a right angle.
Co-occurrence: A = {1, 3, 4, 6} and B = {2, 3, 5, 6} over the universe {1..6}.
- v_A = (1, 0, 1, 1, 0, 1) and v_B = (0, 1, 1, 0, 1, 1).
<v_A, v_B>= 2. The common elements are {3, 6}.
Matrix inner product: A = [[2, 4], [1, 3]], B = [[1, −1], [0, 2]].
<A, B>= 2 − 4 + 0 + 6 = 4.
Why it matters in ML/AI
- Attention scores are q^T k, dot products between a query and keys.
- Cosine similarity between embeddings drives semantic search and RAG retrieval. The live session's example: "bus·car" is high, "bus·man" is near 0, "good·bad" is negative.
- A single neuron before activation is w^T x + b.
- The
<y, Ax> = <A^T y, x>identity is why backprop multiplies by W^T.
Exam traps
- A dot product of two vectors is a scalar. Don't write it as a matrix.
<u + v, u + v>has 2, not . You need the commutativity step to combine the two cross terms.- The zero vector is orthogonal to everything.
<A, B> = tr(A^T B), not tr(AB).
Blog angle: "The dot product is the most important operation in AI: from attention to semantic search."
- The shadow picture: projection length × length.
- Cosine similarity is a dot product with the size normalised away.
- The transpose trick
<y, Ax> = <A^T y, x>and why gradients flow backwards through W^T.
Source tag: Course slides (Ch 7) + Live 10 Oct (AI outline: word similarity examples).
2.7 Norms, angles, orthogonal decomposition & inequalities (Ch 8)
In one line: A norm measures the size of a vector. With the dot product, it gives you distance, angle, projection, and the two inequalities that every proof uses.
Plain-English explanation
Three common vector norms
| Norm | Formula | Picture | (3, 4) |
|---|---|---|---|
| 2-norm (Euclidean) | √(x_1² + … + x_n²) | straight-line distance | 5 |
| 1-norm (Manhattan) | |x_1| + … + |x_n| | city-block / taxicab distance (like a delivery route on a grid) | 7 |
| ∞-norm (Chebyshev) | max |x_i| | the worst single coordinate | 4 |
Matrix norm (Frobenius):
||A||_F = √(Σ A_ij²) = ||vec(A)||_2 = √tr(A^T A).- Its square equals the sum of the squared column norms, and also the sum of the squared row norms.
What makes something a norm. It needs four properties:
- Non-negativity: ||x|| ≥ 0.
- Homogeneity: ||cx|| = |c|·||x||. Note the absolute value.
- Definiteness: ||x|| = 0 ⇔ x = 0.
- Triangle inequality: ||x + y|| ≤ ||x|| + ||y||.
Only norms that come from an inner product satisfy ||v|| = √
"If and only if" (⇔) proofs have two separate directions: assume A and prove B, then assume B and prove A. The instructor warns: keep them separate to avoid circular reasoning.
Norm of a sum: ||u + v||² = ||u||² + 2u^T v + ||v||².
- If u ⊥ v, this becomes the Pythagorean theorem: ||u + v||² = ||u||² + ||v||².
- Change v to −v and you get ||u − v||² = ||u||² − 2u^T v + ||v||².
Orthogonal decomposition (projection). Any u can be split into "the part along v" plus "the part perpendicular to v":
u = α v + w, with α = u^T v / ||v||² and w = u − α v, where w ⊥ v.
Derivation in two lines: we want v^T w = 0, so v^T(u − αv) = 0, which gives α = u^T v / v^T v. The instructor says to remember this two-step logic rather than memorise the formula.
Cauchy-Schwarz: |u^T v| ≤ ||u|| ||v||, with equality iff u and v are parallel.
- Proof idea: ||u||² = (u^T v)²/||v||² + ||w||² ≥ (u^T v)²/||v||².
- Picture: a shadow can never be longer than the stick.
Triangle inequality from Cauchy-Schwarz:
- ||u + v||² ≤ ||u||² + 2||u|| ||v|| + ||v||² = (||u|| + ||v||)².
- Equality holds when u is a non-negative multiple of v.
Reverse triangle inequality: ||u − v|| ≥ | ||u|| − ||v|| |.
- Trick: write u = (u − v) + v and apply the ordinary triangle inequality.
Angle:
cos θ = u^T v / (||u|| ||v||). Cauchy-Schwarz guarantees this lies in [−1, 1].- θ = 0: same direction.
- θ = 90° (π/2): orthogonal.
- θ = 180°: opposite directions.
Orthonormal vectors: v_i^T v_j = 0 for i ≠ j, and ||v_i|| = 1.
Stacked vectors: ||[x_1; x_2]||² = ||x_1||² + ||x_2||².
Cost: about 2n flops for a vector norm and 2n² for the Frobenius norm of an n×n matrix.
Parallelogram law (Assignment 3 Q1):
||u + v||² + ||u − v||² = 2(||u||² + ||v||²).- Proof: add the two expansions above. The ±2u^T v cross terms cancel.
Young's / "ε-trick" (Live 10–11 Oct):
2a^T b ≤ ε||a||² + (1/ε)||b||²for any ε > 0.- Why it holds:
||√ε a − b/√ε||² ≥ 0. Expand it and rearrange. - Use it whenever you have a product and need sums of squares.
Worked examples
(1) Norms of x = (3, −4, 12):
- ||x||_1 = 3 + 4 + 12 = 19.
- ||x||_2 = √(9 + 16 + 144) = √169 = 13.
- ||x||_∞ = 12.
(2) Orthogonal decomposition of u = (4, 2) along v = (1, 1):
- u^T v = 4 + 2 = 6 and ||v||² = 2, so α = 6/2 = 3.
- The part along v is 3·(1, 1) = (3, 3).
- w = u − (3, 3) = (1, −1).
- Check: w^T v = 1 − 1 = 0 ✓, and (3, 3) + (1, −1) = (4, 2) ✓.
The slide example works the same way: u = (2, 3) and v = (1, 1/3) give α = 2.7 and w = (−0.7, 2.1).
(3) Parallelogram law in use. Given ||u + v|| = 6, ||u − v|| = 4 and ||u|| = 3, find ||v||.
- 36 + 16 = 2(9 + ||v||²), so 26 = 9 + ||v||², so ||v||² = 17.
- For u^T v, subtract the two expansions: ||u + v||² − ||u − v||² = 4u^T v, so u^T v = (36 − 16)/4 = 5.
(4) Assignment 3 Q3 (official answer). Find u ∥ (1, 3) and v ⊥ (1, 3) with u + v = (1, 2).
- Set u = α(1, 3) and v = (v_1, v_2). Then v_1 + 3v_2 = 0, α + v_1 = 1 and 3α + v_2 = 2.
- Solving gives α = 7/10, so u = (0.7, 2.1) and v = (0.3, −0.1).
- This is exactly orthogonal decomposition: α = (1, 2)·(1, 3)/||(1, 3)||² = 7/10.
Why it matters in ML/AI
- L2 regularisation (ridge, weight decay) penalises ||w||_2². L1 (lasso) penalises ||w||_1 and pushes weights to exactly zero.
- Normalising embeddings (u/||u||) turns dot products into cosine similarities. Most vector databases do this.
- Projection is the heart of least squares, PCA and Gram-Schmidt.
- The ε-trick appears in every convergence proof for SGD.
- Gradient clipping caps ||g||.
Exam traps
- Homogeneity is |c|·||x||. Forgetting the absolute value loses marks.
- Never square an inequality blindly. −5 < 4, but 25 > 16. Square only when both sides are ≥ 0 (norms are; inner products may not be).
- "For all α, β" (Assignment 3 Q2) means one example is not a proof. Expand in general: the difference is (α² − β²)(||u||² − ||v||²), which is zero for all α, β iff ||u|| = ||v||.
- Projection uses ||v||² in the denominator, not ||v||.
- The 1-norm and ∞-norm are not induced by any inner product.
Blog angle: "Cauchy-Schwarz in one picture: why a shadow can't be longer than the stick (and why cosine similarity works)."
- Three norms, three distance notions: crow, taxi, worst coordinate.
- Projection as "how much of u lives along v". It is the core of regression and PCA.
- The ε-trick: turning products into sums, the most useful inequality in ML theory.
Source tag: Course slides (Ch 8) + Assignment 3 (official solutions) + Live 10 & 11 Oct (AI outlines; corrected one outline claim that norms are "strictly positive", since ||0|| = 0).
2.8 Linear functions (Ch 9)
In one line: A function is linear if "scale and add the inputs" gives "scale and add the outputs". Every such function is a dot product (scalar output) or a matrix (vector output).
Plain-English explanation
Notation: f : R^n → R takes vectors to scalars. f : R^n → R^m takes vectors to vectors. The input set is the domain; the output set is the co-domain.
Linear means superposition:
- Additivity: f(u + v) = f(u) + f(v).
- Homogeneity: f(αu) = αf(u).
- Combined: f(α_1 v_1 + α_2 v_2) = α_1 f(v_1) + α_2 f(v_2).
Big result (the Riesz representation theorem, finite-dimensional case). Every linear f : R^n → R is f(x) = a^T x for a unique a, and you can find it by feeding in the unit vectors: a = (f(e_1), f(e_2), …, f(e_n)).
- Why: x = Σ x_i e_i, so f(x) = Σ x_i f(e_i) = a^T x.
- Uniqueness: if u^T x = v^T x for all x, then putting x = e_i gives u_i = v_i.
Vector-valued version: each output is its own linear function a_i^T x. Stack them as rows and you get f(x) = Ax.
- 3Blue1Brown: "a linear transformation is completely determined by where it sends the basis vectors". Those images are the columns of A.
Software analogy: a linear function is like a pure, stateless pricing function with no fixed fee. Double the order and the price doubles. Combine two orders and the price is the sum. Once you know the price of one unit of each item (f(e_i)), you know the price of every order.
Examples:
- Scaling: S(x) = Diag(s)x.
- Projection onto the x-axis: p(x, y) = (x, 0).
- In 3D, P = [[1,0,0],[0,1,0],[0,0,0]] drops z. Projections are idempotent: P² = P, because projecting twice is the same as projecting once.
Non-examples:
- f(x) = a^T x + c with c ≠ 0 is affine, not linear, because f(0) ≠ 0.
- ||x||², max_i x_i and |x| are not linear.
Worked example
f(x) = 2x_1 − x_2 + 3x_3.
- f(e_1) = 2, f(e_2) = −1 and f(e_3) = 3, so a = (2, −1, 3).
- f(1, 2, 3) = 2 − 2 + 9 = 9.
Assignment 4 Q2: f(x) = (||x − c||² − ||c||²) − (||x − d||² − ||d||²).
- Expand: ||x − c||² = ||x||² − 2c^T x + ||c||². So the first bracket is ||x||² − 2c^T x.
- In the same way, the second bracket is ||x||² − 2d^T x.
- Subtract: f(x) = −2c^T x + 2d^T x = 2(d − c)^T x.
- So f is linear, with a = 2(d − c). (Checked numerically with random c, d, x.)
Why it matters in ML/AI
- A linear layer is a linear function. Adding the bias makes it affine. With the "append a 1" trick it becomes linear in a bigger space.
- Linear probes in interpretability: if a concept is linearly decodable, there is an
awith concept ≈ a^T h. - The Riesz result is why every linear readout or classifier is "a dot product with a weight vector".
Exam traps
- Check f(0) = 0 first. If f(0) ≠ 0, the function is not linear.
- Showing linearity needs the general superposition argument, not a numeric example.
- Projection matrices satisfy P² = P. They are generally not invertible (they lose information).
- In Assignment 4 Q2 type problems, expand the norms. The ||x||² terms must cancel. If they don't, the function isn't linear.
Blog angle: "Every linear function is a dot product: the theorem behind linear probes and readout heads."
- Superposition explained with pricing or shipping costs.
- "Feed it the unit vectors" recovers the weights: a 3-line proof.
- Why the bias breaks linearity, and the homogeneous-coordinates fix.
Source tag: Course slides (Ch 9) + Assignment 4 Q2 (solution derived here, no official solution yet). The slide's "Reisz" is the Riesz representation theorem (textbook fill-in).
2.9 Linear systems, inverses, orthogonal matrices & least squares (Ch 10)
In one line: Solving Ax = b means finding the input that the machine A turns into b. If no exact answer exists, least squares finds the input whose output is closest to b. That is linear regression.
Plain-English explanation
Linear system: m equations a_i^T x = b_i, written compactly as Ax = b. Per the slides, linear algebra "is all about solving linear systems, exactly or approximately".
Inverse (square matrices only):
- B is the inverse of A if AB = BA = I. It is written A^(−1).
- Invertible / non-singular: the inverse exists.
- Singular: it doesn't.
- Picture: A^(−1) is the "undo" button. A singular A squashes space flat (for example, onto a line), and you can't un-squash.
- Properties (all proved on the slides):
- The inverse is unique: B = BI = B(AC) = (BA)C = C.
- (AB)^(−1) = B^(−1) A^(−1). Order reverses again, like transpose.
- (A^(−1))^(−1) = A.
- (A^T)^(−1) = (A^(−1))^T.
- 2×2 formula: [[a, b], [c, d]]^(−1) = (1/(ad − bc))·[[d, −b], [−c, a]]. It fails when ad = bc.
- Diagonal matrices invert entry by entry: Diag(2, 3)^(−1) = Diag(1/2, 1/3).
- If A is invertible, then x = A^(−1) b is the unique solution. Computing A^(−1) costs about n³.
Orthogonal matrices Q (square) satisfy Q^T Q = Q Q^T = I, i.e. Q^(−1) = Q^T.
- The columns are orthonormal, and so are the rows.
- Example: the rotation R(θ) = [[cos θ, −sin θ], [sin θ, cos θ]].
- They preserve lengths and angles: ||Qu|| = ||u|| and
= . Think "rigid rotation or reflection". - So solving Qx = b is just x = Q^T b, which costs n² instead of n³.
- Caution: a tall matrix with orthonormal columns (m > n) has A^T A = I_n but A A^T ≠ I_m. It is not called orthogonal.
Gradients and minimisation: at a minimum of a smooth h(x), every partial derivative is zero: ∇h(x*) = 0.
- Scalar example: h(x) = log x − ax has h'(x) = 1/x − a = 0, so x* = 1/a. (This point is actually the maximum of that function. The slide uses it only to illustrate setting the derivative to zero.)
- Vector example: h(x) = ||x − b||² has ∂h/∂x_i = 2(x_i − b_i) = 0, so x* = b.
Least squares (LS). When A is tall (m > n: more equations than unknowns), Ax = b usually has no solution. So minimise the squared error instead:
x* = argmin_x ||Ax − b||²
- Set the gradient to zero: ∇h = 2(A^T A x − A^T b) = 0. This gives the normal equations: A^T A x = A^T b.
- If A^T A is invertible (which needs m ≥ n and independent columns), then x* = (A^T A)^(−1) A^T b.
- Geometric picture (the key insight). Ax ranges over the column space of A (a plane, say). b sticks out of that plane. The closest point Ax* is the foot of the perpendicular from b. The residual r = b − Ax* is orthogonal to every column of A, which is exactly A^T r = 0, the normal equations. Least squares is orthogonal projection.
- n = 1 case: the best multiple of a to approximate b is x* = a^T b / a^T a. This is the projection coefficient α from the norms chapter.
- Fitting a line y = wx + b: stack the rows [x_i, 1] into X and solve min ||y − X[w; b]||². Closed form:
- w* = Σ(x_i − x̄)(y_i − ȳ) / Σ(x_i − x̄)²
- b* = ȳ − w* x̄
- Fitting a parabola: use columns [x², x, 1]. It is still linear in the unknowns, so it is still least squares.
- History: Gauss used least squares at age 18 (1795) and used it to predict where the asteroid Ceres would reappear (1801). Legendre published first (1805).
Worked examples
(1) Inverse: A = [[2, 1], [5, 3]].
- ad − bc = 6 − 5 = 1.
- A^(−1) = (1/1)·[[3, −1], [−5, 2]] = [[3, −1], [−5, 2]].
- Check: [[2,1],[5,3]]·[[3,−1],[−5,2]] = [[6 − 5, −2 + 2], [15 − 15, −5 + 6]] = I ✓.
(2) Rotation: rotate p = (2, 1) by 45°.
- R = [[0.7071, −0.7071], [0.7071, 0.7071]].
- p' = (0.7071·2 − 0.7071·1, 0.7071·2 + 0.7071·1) = (0.7071, 2.1213).
- Length check: ||p'|| = √5 = ||p|| ✓, as rotation preserves length.
(3) Least-squares line through (1, 1), (2, 2), (3, 2), (4, 4).
- X = [[1,1],[2,1],[3,1],[4,1]] and y = (1, 2, 2, 4).
- X^T X = [[Σx², Σx], [Σx, m]] = [[30, 10], [10, 4]]. X^T y = (Σxy, Σy) = (27, 9).
- Solve [[30, 10], [10, 4]]·[w; b] = [27; 9]: - From the second row: b = (9 − 10w)/4. - Substitute into the first row: 30w + 10(9 − 10w)/4 = 27, so 30w + 22.5 − 25w = 27, so 5w = 4.5, so w = 0.9 and b = 0.
- Cross-check with the centred formula. x̄ = 2.5 and ȳ = 2.25. - Σ(x − x̄)(y − ȳ) = 1.875 + 0.125 − 0.125 + 2.625 = 4.5. - Σ(x − x̄)² = 5. - So w = 4.5/5 = 0.9 ✓ and b = 2.25 − 0.9·2.5 = 0 ✓.
- Residuals r = y − Xw = (0.1, 0.2, −0.7, 0.4). Sum of squares = 0.7. Check X^T r = (0, 0) ✓, so the residual is orthogonal to the columns.
(4) Assignment 4 Q4 numerically: a = (1, 2, 2), b = (3, 0, 3).
- x* = a^T b / a^T a = 9/9 = 1.
- Residual: ||a·1 − b||² = ||(−2, 2, −1)||² = 9.
- Formula check: ||b||² sin²θ = 18·(1 − 81/(9·18)) = 18·0.5 = 9 ✓.
Why it matters in ML/AI
- Linear regression is literally least squares. The normal equations are its closed-form solution, and gradient descent on MSE converges to the same answer.
- The "residual ⊥ features" condition is why OLS residuals are uncorrelated with every feature.
- Orthogonal matrices keep signal norms stable. That is why orthogonal weight initialisation and rotations (RoPE positional encoding uses 2×2 rotation blocks) are popular.
- Ridge regression changes the normal equations to (A^T A + λI)x = A^T b, which is always invertible.
Exam traps
- Only square matrices have (two-sided) inverses. "Orthogonal" requires square.
- (AB)^(−1) = B^(−1) A^(−1), not A^(−1) B^(−1).
- In practice, don't compute A^(−1) to solve Ax = b. Factor A instead (LU/QR, next section).
- Least squares needs A^T A invertible. This requires m ≥ n (the slide says m > n; m = n is fine too) and independent columns.
- In "find θ for the closest point on a line" (Assignment 4 Q3), rewrite the point as v + θ(u − v) and it becomes the n = 1 LS problem:
- θ* = (p − v)^T(u − v) / ||u − v||².
- Rotations: R(θ)R(ω) = R(θ + ω) = R(ω)R(θ). 2-D rotations do commute. In 3-D they generally don't.
Blog angle: "Least squares is just dropping a perpendicular: the geometry behind linear regression."
- No exact solution? Then find the closest reachable point.
- Normal equations = "the error is perpendicular to everything the model can express".
- From Gauss tracking Ceres to
sklearn.LinearRegression.
Source tag: Course slides (Ch 10) + Assignment 4 (solutions derived here; no official solutions yet). Textbook fill-in for the projection geometry.
2.10 LU and QR factorisation (Ch 11)
In one line: Break a hard matrix into easy pieces (triangles, rotations). Then solving Ax = b becomes two quick substitution passes.
Plain-English explanation
Why factor? Triangular systems are easy. In Ux = b (U upper triangular), the last equation has one unknown. Solve it, plug it into the equation above, and repeat. This is back-substitution:
x_i = (b_i − Σ_{j>i} U_ij x_j) / U_ii, which needs every U_ii ≠ 0.
It costs about n² flops. Lower-triangular systems use forward-substitution, also about n².
LU decomposition: A = LU (L lower triangular, U upper triangular).
- It is basically Gaussian elimination with the multipliers saved in L.
- It is not unique. It may not exist (for example, if the top-left entry is 0).
- PLU (A = PLU) always exists. P is a permutation matrix (a row-shuffled identity):
- Left-multiplying by P permutes rows. Right-multiplying permutes columns.
- P is orthogonal: P^(−1) = P^T.
- To solve Ax = b: 1. Factor A = LU (about n³, done once). 2. Solve Ly = b (n²). 3. Solve Ux = y (n²).
- Payoff: with many right-hand sides b_1, b_2, …, you pay n³ once and then only n² each. It is like building a database index once and then querying cheaply.
QR decomposition: A = QR, with Q orthogonal and R upper triangular.
- To solve: Qy = b gives y = Q^T b (n², no real solving). Then solve Rx = y by back-substitution.
- To invert: A^(−1) comes from solving R x_i = Q^T e_i for each column, about n³ in total.
- Picture: Q is a rotation that lines up the coordinate system with A's columns. R records how each column is built from the ones before it.
- QR is the numerically stable way to do least squares. The normal equations become R x = Q^T b, which avoids forming A^T A.
2×2 general formulas (Assignment 5 Q1–Q2), for a ≠ 0
LU: [[a, b], [c, d]] = [[1, 0], [x, 1]]·[[u, v], [0, w]].
- Multiply out the right side: [[u, v], [xu, xv + w]].
- Match entries: u = a, v = b, x = c/a, w = d − bc/a.
QR with rotation Q = R(θ):
- The first column of A must equal u·(cos θ, sin θ).
- So u = √(a² + c²), cos θ = a/u, sin θ = c/u. Equivalently θ = atan2(c, a). (You could also take u negative and θ shifted by 180°.)
- Second column: (b, d) = v(cos θ, sin θ) + w(−sin θ, cos θ).
- So v = (ab + cd)/u and w = (ad − bc)/u.
Worked examples
(1) Back-substitution (slide): [[2, 4, 5], [0, 3, −1], [0, 0, 1]]·x = (−1, −4, 1).
- x_3 = 1/1 = 1.
- x_2 = (−4 − (−1)(1))/3 = −3/3 = −1.
- x_1 = (−1 − 4(−1) − 5(1))/2 = (−1 + 4 − 5)/2 = −1.
- So x = (−1, −1, 1).
(2) Solve Ax = b with the slide's LU. A = [[1, 3, 2], [2, 7, 3], [4, 13, 10]] = LU, with L = [[1,0,0],[2,1,0],[4,1,1]] and U = [[1,3,2],[0,1,−1],[0,0,3]]. Take b = (6, 12, 27).
- Forward: y_1 = 6, y_2 = 12 − 2·6 = 0, y_3 = 27 − 4·6 − 1·0 = 3. So y = (6, 0, 3).
- Back: x_3 = 3/3 = 1, x_2 = 0 − (−1)(1) = 1, x_1 = 6 − 3·1 − 2·1 = 1.
- So x = (1, 1, 1). Check: row 1 gives 1 + 3 + 2 = 6 ✓.
(3) Assignment 5 Q1 check with [[1, 2], [3, 4]].
- x = 3/1 = 3, u = 1, v = 2, w = 4 − 2·3/1 = −2.
- Check: [[1,0],[3,1]]·[[1,2],[0,−2]] = [[1, 2], [3, 6 − 2]] = [[1, 2], [3, 4]] ✓.
(4) QR of the same matrix.
- u = √(1 + 9) = √10 ≈ 3.162, and θ = atan2(3, 1) ≈ 71.57°.
- v = (1·2 + 3·4)/√10 = 14/√10 ≈ 4.427.
- w = (1·4 − 2·3)/√10 = −2/√10 ≈ −0.632.
- Multiplying back gives [[1, 2], [3, 4]] ✓.
Why it matters in ML/AI
numpy.linalg.solveandlstsqcall LU or QR under the hood. Knowing this explains their speed and stability.- The many-right-hand-sides trick appears in Gaussian processes, Kalman filters and second-order optimisers.
- QR (Gram-Schmidt) is used to orthogonalise weight matrices and in some optimisers that re-orthogonalise updates.
Exam traps
- Back-substitution needs non-zero diagonal entries U_ii.
- LU is not unique and may not exist. PLU always exists.
- Solve-cost summary: factorisation ≈ n³, each triangular solve ≈ n², orthogonal solve (Q^T b) ≈ n². Examiners like "which is cheaper" questions.
- Left vs right multiplication by a permutation: left moves rows, right moves columns.
- In the 2×2 QR, w = det(A)/u. A quick check: det(A) = det(Q)det(R) = 1·u·w.
Blog angle: "Why your solver never inverts a matrix: LU, QR and the art of solving Ax = b."
- Triangular systems are dominoes: solve one, and the next falls.
- Factor once, solve many times: the database-index analogy.
- QR as "rotate to make it triangular", and why it is the stable route to regression.
Source tag: Course slides (Ch 11) + Assignment 5 Q1–Q2 (solutions derived here and verified numerically).
2.11 Singular value decomposition (SVD) (Ch 12)
In one line: Every matrix, whatever its shape, is "rotate, then stretch along the axes, then rotate again". The stretch factors (singular values) tell you everything important about it.
Plain-English explanation
The decomposition: A = U Σ V^T, where A is m×n.
- U (m×m) and V (n×n) are orthogonal.
- Σ (m×n) is zero except for the top-left block Σ_1 = Diag(σ_1, …, σ_r).
- The σ_i > 0 are the singular values, sorted σ_1 ≥ σ_2 ≥ … ≥ σ_r.
- It always exists, for every matrix.
3Blue1Brown picture. To compute b = Ax = U Σ V^T x:
- V^T x: rotate (or reflect) x in the input space R^n.
- Σ(…): stretch each axis by σ_i. Drop some coordinates (σ = 0), or pad with zeros if m > n. Now you are in R^m.
- U(…): rotate in the output space R^m.
So a matrix maps the unit circle to an ellipse. The σ_i are the semi-axis lengths of that ellipse, the columns of V are the input directions that map onto the axes, and the columns of U are the axis directions.
Rank:
- rank(A) = r = the number of non-zero singular values, and r ≤ min(m, n).
- Plain English: the number of independent directions A can actually output.
Inverse: if A is square and full-rank, A^(−1) = V Σ^(−1) U^T, i.e. un-rotate, un-stretch (1/σ_i), un-rotate.
Compact (economic) SVD: A = U_1 Σ_1 V_1^T keeps only the r non-zero σ's.
- U_1 (m×r) and V_1 (n×r) have orthonormal columns, but they are not square, so they are not "orthogonal matrices".
Uniqueness:
- The singular values are unique.
- U and V are not. For example, (−U)Σ(−V)^T also works.
- The identity has infinitely many SVDs: I = U I U^T for any orthogonal U.
Rank-one expansion (outer-product view of multiplication):
A = σ_1 u_1 v_1^T + σ_2 u_2 v_2^T + … + σ_r u_r v_r^T
- Each term is a rank-1 "layer". For an image, each term is a simple striped pattern, and the image is the sum of these patterns.
- Because σ's are sorted, later terms matter less. Keep the first k for a rank-k approximation. This is the optimal rank-k approximation (the Eckart-Young theorem, textbook fill-in).
- Storage for rank-k of an m×n matrix: m·k + k + k·n numbers (the U columns, the σ's, the V columns) versus m·n.
Classic examples:
- The all-ones n×n matrix 11^T = z·n·z^T with z = 1/√n. Rank 1, σ_1 = n.
- A rank-1 matrix xy^T has compact SVD (x/||x||)·(||x|| ||y||)·(y/||y||)^T. So σ_1 = ||x|| ||y||.
- SVD of A^T: A^T = V Σ^T U^T. Same non-zero σ's, so rank(A) = rank(A^T) (Assignment 5 Q4b).
- A·V = U Σ (multiply A = UΣV^T on the right by V). Its SVD is U Σ I^T.
- A·V² = U Σ V. Since V^T is also orthogonal, this is an SVD with right factor (V^T)^T, so the singular values are unchanged.
Worked examples
(1) Assignment 5 Q3: A = [[1, 4, 2], [2, 8, 4], [−1, −4, −2]].
- Every row is a multiple of (1, 4, 2): row 2 = 2× row 1 and row 3 = −1× row 1. So A = x y^T with x = (1, 2, −1) and y = (1, 4, 2).
- ||x|| = √(1 + 4 + 1) = √6 and ||y|| = √(1 + 16 + 4) = √21.
- Compact SVD: A = u_1 σ_1 v_1^T with u_1 = (1, 2, −1)/√6, σ_1 = √6·√21 = √126 = 3√14 ≈ 11.225, and v_1 = (1, 4, 2)/√21.
- Rank = 1. numpy confirms the singular values are (11.225, 0, 0).
(2) A small full-rank SVD: A = [[3, 0], [4, 5]].
- Claimed factors: σ_1 = √45 ≈ 6.708 and σ_2 = √5 ≈ 2.236, with v_1 = (1, 1)/√2, v_2 = (1, −1)/√2, u_1 = (1, 3)/√10, u_2 = (3, −1)/√10.
- Check Av_1 = (3, 9)/√2. Its length is √90/√2 = √45 = σ_1 ✓, and its direction is (1, 3)/√10 = u_1 ✓.
- Check Av_2 = (3, −1)/√2. Its length is √10/√2 = √5 = σ_2 ✓.
- Sanity check: ||A||_F² = 9 + 0 + 16 + 25 = 50 = σ_1² + σ_2² = 45 + 5 ✓. In general ||A||_F² = Σ σ_i².
- Best rank-1 approximation: σ_1 u_1 v_1^T = [[1.5, 1.5], [4.5, 4.5]]. Its Frobenius error is exactly σ_2 = √5 ≈ 2.236.
- (How to find these by hand uses eigenvalues of A^T A = [[25, 20], [20, 25]], which come later in the course.)
(3) Image compression (slide). A 402×600 image has 241,200 pixels.
| k | Stored numbers | Compression ratio |
|---|---|---|
| 200 | 402·200 + 200 + 200·600 = 200,600 | ≈ 1.2× |
| 100 | 100,300 | ≈ 2.4× |
| 50 | 50,150 | ≈ 4.8× |
(4) Assignment 5 Q5: A = uv^T + xy^T, with no zero entries.
- rank 0 (A = 0): happens iff xy^T = −uv^T, i.e. x = αu and y = −v/α for some α ≠ 0.
- rank ≤ 1: happens iff x ∥ u or y ∥ v. Write x = αu; then A = u(v + αy)^T. So rank = 1 iff (x ∥ u or y ∥ v) and A ≠ 0.
- Otherwise the rank is 2. Checked numerically: x = 2u gives rank 1, a cancelling choice gives rank 0, and random vectors give rank 2.
Why it matters in ML/AI
- PCA: centre the data matrix and take its SVD. The top right-singular vectors are the principal directions, and σ_i²/(m − 1) are the explained variances.
- Embeddings / LSA: the SVD of a word-document or co-occurrence matrix gives dense word vectors, the precursor to word2vec.
- LoRA: a fine-tuning update ΔW = BA is constrained to low rank r. It is the rank-k approximation idea used as a training trick. Model compression truncates the SVD of weight matrices.
- Recommenders: Netflix-prize matrix factorisation is a low-rank approximation of the user × item matrix.
- The condition number σ_1/σ_n says how numerically fragile solving Ax = b is.
Exam traps
- rank = the number of non-zero σ's. For a rank-1 xy^T, σ_1 = ||x|| ||y||. Normalise x and y to unit vectors for U and V.
- Singular values are non-negative. Push any sign into U or V.
- In the compact SVD, U_1 and V_1 have orthonormal columns but are not orthogonal matrices unless square.
- SVD is not unique (signs, and any rotation within repeated σ's). The σ's themselves are unique.
- (AV) means you multiply on the right, so the V^T cancels: AV = UΣ.
- Rank-k storage: don't forget the k singular values in the middle term.
Blog angle: "Every matrix is rotate–stretch–rotate: the SVD, from JPEG-style compression to LoRA."
- The circle-to-ellipse picture: what σ's, U and V mean geometrically.
- An image as a sum of rank-1 layers. Keep the top k and you have compressed it.
- LoRA, PCA and recommenders are three faces of the same low-rank idea.
Source tag: Course slides (Ch 12) + Assignment 5 Q3–Q5 (solutions derived here and verified numerically). Textbook fill-in: Eckart-Young theorem, ||A||_F² = Σσ², PCA link.
2.12 Live sessions 17 Oct & 18 Oct 2026
Not covered, because no material is available. No AI outline or slides exist for these sessions yet. Judging by the pattern of earlier sessions (one concept session and one assignment-discussion session per weekend), they probably covered Assignment 4 (linear functions, least squares, orthogonal matrices) and/or LU/QR/SVD. Watch the recordings when the portal is back up (after 25 Oct).
3. Formula / cheat sheet
| Topic | Formula / fact | Plain-English reminder |
|---|---|---|
| Subvector | a_{r:s} has s − r + 1 entries |
inclusive range |
| Linear combination | α_1 a_1 + … + α_m a_m |
weighted mix of vectors |
| Unit-vector expansion | x = Σ x_i e_i |
entries are weights on axes |
| Flops: add N vectors of length L | (N − 1)L | |
| Subspace test | 0 ∈ W; closed under +; closed under scaling (field F) | check zero first |
| Matrix-vector | Av = Σ v_j a_j; (Av)_i = row_i · v |
mix columns of A |
| Columns/rows | Ae_i = a_i; A1 = row sums; A^T 1 = column sums |
|
| Matrix product | C_ij = Σ_k A_ik B_kj; (m×n)(n×p) = m×p |
inner dims match |
| Outer-product view | AB = Σ_k a_k b_k^T (columns of A × rows of B) |
sum of rank-1s |
| Transpose of product | (AB)^T = B^T A^T |
reverse order |
| Trace | tr(AB) = tr(BA); tr(ABC) = tr(BCA) = tr(CAB) |
cyclic only |
| Gram matrix | G = A^T A, G_ij = a_i^T a_j, symmetric |
column dot products |
| Flops | dot 2n − 1; mat-vec ≈ 2n²; mat-mat ≈ 2n³; triangular solve ≈ n²; LU/QR ≈ n³ | |
| Inner product | <u, v> = u^T v = ||u|| ||v|| cos θ |
similarity |
| Move matrix across | <y, Ax> = <A^T y, x> |
|
| Matrix inner product | <A, B> = Σ A_ij B_ij = tr(A^T B) |
|
| Norms | ||x||_1 = Σ|x_i|, ||x||_2 = √(x^T x), ||x||_∞ = max|x_i|, ||A||_F = √tr(A^T A) |
taxi / crow / worst |
| Norm axioms | ≥ 0; ||cx|| = |c| ||x||; ||x|| = 0 ⇔ x = 0; triangle |
|
| Norm of sum | ||u ± v||² = ||u||² ± 2u^T v + ||v||² |
vector (a ± b)² |
| Pythagoras | u ⊥ v ⇒ ||u + v||² = ||u||² + ||v||² |
|
| Parallelogram | ||u + v||² + ||u − v||² = 2(||u||² + ||v||²) |
|
| Polarisation | u^T v = (||u + v||² − ||u − v||²)/4 |
|
| Projection | α = u^T v / ||v||², w = u − αv ⊥ v |
shadow of u on v |
| Cauchy-Schwarz | |u^T v| ≤ ||u|| ||v|| (= iff parallel) |
shadow ≤ stick |
| Triangle / reverse | ||u + v|| ≤ ||u|| + ||v||; ||u − v|| ≥ | ||u|| − ||v|| | |
|
| ε-trick (Young) | 2a^T b ≤ ε||a||² + ||b||²/ε, ε > 0 |
product → sums |
| Linear function | f(αx + βy) = αf(x) + βf(y) ⇔ f(x) = a^T x, a_i = f(e_i) |
f(0) must be 0 |
| Vector linear map | f(x) = Ax |
|
| Projection matrix | P² = P |
idempotent |
| Inverse | AA^(−1) = A^(−1)A = I; (AB)^(−1) = B^(−1)A^(−1); (A^T)^(−1) = (A^(−1))^T |
|
| 2×2 inverse | [[a,b],[c,d]]^(−1) = [[d,−b],[−c,a]]/(ad − bc) |
|
| Orthogonal Q | Q^T Q = QQ^T = I; ||Qx|| = ||x||; solve Qx = b by x = Q^T b |
rotation |
| Rotation | R(θ) = [[cos, −sin], [sin, cos]]; R(θ)R(ω) = R(θ + ω) |
|
| Least squares | min ||Ax − b||² ⇒ A^T A x = A^T b ⇒ x* = (A^T A)^(−1) A^T b |
residual ⊥ columns |
| LS, n = 1 | x* = a^T b / a^T a; residual² = ||b||² sin²θ |
|
| Line fit | w = Σ(x − x̄)(y − ȳ)/Σ(x − x̄)², b = ȳ − w x̄ |
|
| Nearest point on line through u, v | θ* = (p − v)^T(u − v)/||u − v||² |
|
| Back-substitution | x_i = (b_i − Σ_{j>i} U_ij x_j)/U_ii |
needs U_ii ≠ 0 |
| LU 2×2 | x = c/a, u = a, v = b, w = d − bc/a | |
| QR 2×2 (rotation) | u = √(a² + c²), θ = atan2(c, a), v = (ab + cd)/u, w = (ad − bc)/u | |
| Solve via LU / QR | Ly = b, Ux = y / y = Q^T b, Rx = y | |
| SVD | A = UΣV^T = Σ σ_i u_i v_i^T; rank = #(σ_i > 0) |
rotate–stretch–rotate |
| SVD facts | A^(−1) = VΣ^(−1)U^T; A^T = VΣ^T U^T; AV = UΣ; ||A||_F² = Σσ_i² |
|
| Rank-1 | xy^T: σ_1 = ||x|| ||y||, u = x/ |
|
| Rank-k storage | mk + k + kn vs mn |
4. Assignment-pattern analysis
What has been set so far
| Assignment | Marks | Topics | Question types |
|---|---|---|---|
| A1 (22 Sep, practice) | ~20 | dimension/validity of vector expressions; sizes of 0/1 blocks; storage + flops + time; displacement sum; subspace tests incl. field question | conceptual checks, small numericals |
| A2 | 10 | block-matrix truth claims; when xy^T = yx^T; nilpotent example; circular shift Aⁿx | true/false-with-reason, short derivation, construct an example, pattern-finding |
| A3 | 10 | parallelogram law; ‖αu + βv‖ = ‖αv + βu‖ ⇔ ‖u‖ = ‖v‖; decomposition along (1, 3); reverse triangle; 8‖x − y‖² ≤ 9‖x − a‖² + 72‖y − a‖² | 4 proofs + 1 small numerical |
| A4 | 10 | rotations compose and commute; show f is linear and find a; nearest point on a line (argmin); residual = ‖b‖² sin²θ; find α to make A orthogonal | derivations, small optimisation, 1 numerical |
| A5 (17 Oct) | 10 | symbolic 2×2 LU; symbolic 2×2 QR via rotation; SVD of a rank-1 3×3 by hand; SVD of AV, AV², Aᵀ and rank(A) = rank(Aᵀ); rank of uvᵀ + xyᵀ | symbolic computation, "by hand" SVD, conceptual rank reasoning |
Patterns
- Proofs vs numericals vs conceptual: roughly 45% short proofs/derivations, 30% symbolic computation, 25% small numericals or true/false-with-reason. Numbers are always tiny (2×2, 3×3, or vectors like (1, 3)). The instructor tests structure, not arithmetic stamina.
- Favourite proof toolkit (most proofs use one of these): 1. Expand ‖u ± v‖² = ‖u‖² ± 2uᵀv + ‖v‖². 2. Look at the (i, j) entry. 3. Use the triangle inequality on a clever split such as u = (u − v) + v. 4. Use the ε-trick 2aᵀb ≤ ε‖a‖² + ‖b‖²/ε. 5. Set a derivative or gradient to zero.
- Iff and "for all" questions recur. You must show both directions and argue in general, not with an example.
- The "find the parameter" style: find α so that A is orthogonal (answer: α = ±1/2), find θ, u, v, w in a factorisation, find α, v in a decomposition. Approach: write the unknowns, match entries, solve the small system.
- Difficulty: each question is 1–2 marks and 5–15 minutes if you know the trick. The hardest items are inequality proofs (A3 Q5, whose official solution is missing; see the question bank's long answers) and the rank-of-a-sum reasoning (A5 Q5).
- Live sessions walk through exactly these problems and emphasise common errors: squaring inequalities, "for all" vs one example, which field.
What the next exam (quiz / online end-sem, 55%) will probably look like
- Format guess (not stated in the material): online, so expect MCQs and numeric-entry questions modelled on assignment problems. Possibly 1–2 short derivations.
- Likely content:
- Validity and shape checks.
- Subspace yes/no (with the field twist).
- Matrix-product properties (AB ≠ BA, transposes, trace, nilpotent and permutation powers).
- Norm and inner-product identities (parallelogram, polarisation, projection coefficient, Cauchy-Schwarz equality case).
- Linearity tests and finding
a. - Inverses and orthogonality (2×2 inverse, α for orthogonality, preserved lengths).
- Least-squares normal equations and a tiny line fit.
- Flop counts (2n², 2n³, n²).
- LU/QR of 2×2, back-substitution.
- SVD of rank-1 matrices, rank from singular values, rank-k storage.
- Likely new material before the end-sem: fundamental subspaces, linear independence, bases, eigenvalues (all listed on the intro slide). Expect them to be examined.
- Preparation plan:
1. Redo A2–A5 without notes.
2. Drill the five-tool proof toolkit above.
3. Do the question bank (
LA_questions.json) under timed conditions. 4. Memorise the cheat sheet's flop counts and SVD facts.
Notes on sources:
- The PDF of Assignment 5 is headed "EE951 Assignment 4, 17 Oct 2026", although the portal lists it as Assignment 5.
- The Assignment 3 solutions PDF has no solution for Q5. A full model solution is in
LA_questions.json→long. - AI-generated live-session outlines were cross-checked against the slides and solutions, and minor errors were corrected silently.