Level 3 — ProductionLinear Algebra Essentials

Linear Algebra Essentials

45 minutes60 marksprintable — key stays hidden on paper

Difficulty: Level 3 — Production (from-scratch derivations, code-from-memory, explain-out-loud) Time limit: 45 minutes Total marks: 60

Instructions: Show all derivations. Where code is requested, write it from memory in plain Python/NumPy. Explain reasoning where asked.


Q1. (10 marks) — Derivation: dot product, angle, projection

(a) Starting from the law of cosines, derive the relationship ab=abcosθ\mathbf{a}\cdot\mathbf{b} = \|\mathbf{a}\|\,\|\mathbf{b}\|\cos\theta. (4)

(b) Given a=(3,4)\mathbf{a} = (3, 4) and b=(4,0)\mathbf{b} = (4, 0), compute the scalar projection of a\mathbf{a} onto b\mathbf{b} and the vector projection of a\mathbf{a} onto b\mathbf{b}. (4)

(c) Explain in one or two sentences why the dot product is 00 exactly when vectors are orthogonal. (2)


Q2. (12 marks) — Eigenvalues, eigenvectors, and decomposition

Let A=[2112]A = \begin{bmatrix} 2 & 1 \\ 1 & 2 \end{bmatrix}.

(a) Derive the eigenvalues from the characteristic polynomial det(AλI)=0\det(A - \lambda I) = 0. (4)

(b) Find a unit eigenvector for each eigenvalue. (4)

(c) Write the eigendecomposition A=QΛQA = Q\Lambda Q^{\top} explicitly, and state why QQ is orthogonal here. (4)


Q3. (10 marks) — Code from memory

(a) Write a NumPy function power_iteration(A, iters=100) that returns the dominant eigenvalue and its eigenvector via power iteration. Include normalization each step and the Rayleigh quotient for the eigenvalue. (6)

(b) Explain out loud (in prose) why power iteration converges to the eigenvector of largest-magnitude eigenvalue, and one condition under which it fails. (4)


Q4. (10 marks) — Gaussian elimination + rank/null space

Consider the system [121243364]x=[134].\begin{bmatrix} 1 & 2 & 1 \\ 2 & 4 & 3 \\ 3 & 6 & 4 \end{bmatrix}\mathbf{x} = \begin{bmatrix} 1 \\ 3 \\ 4 \end{bmatrix}.

(a) Perform Gaussian elimination to row echelon form. (4)

(b) State the rank of the coefficient matrix and give a basis for its null space. (4)

(c) Does a solution exist? If so, give the general solution. (2)


Q5. (10 marks) — Positive definiteness & quadratic forms

Let f(x)=2x12+2x22+2x1x2f(\mathbf{x}) = 2x_1^2 + 2x_2^2 + 2x_1 x_2.

(a) Write ff as a quadratic form xMx\mathbf{x}^\top M \mathbf{x} with MM symmetric. (3)

(b) Determine whether MM is positive definite using both the eigenvalue test and the leading-principal-minor (Sylvester) test. (5)

(c) State what positive definiteness of the Hessian implies for a critical point in optimization. (2)


Q6. (8 marks) — SVD intuition

(a) State the SVD A=UΣVA = U\Sigma V^\top and describe geometrically what each of UU, Σ\Sigma, VV^\top does to a unit sphere. (4)

(b) Explain the relationship between the singular values of AA and the eigenvalues of AAA^\top A. (4)

Answer keyMark scheme & solutions

Q1.

(a) Consider triangle with sides a\mathbf{a}, b\mathbf{b} and ab\mathbf{a}-\mathbf{b}. Law of cosines: ab2=a2+b22abcosθ.\|\mathbf{a}-\mathbf{b}\|^2 = \|\mathbf{a}\|^2 + \|\mathbf{b}\|^2 - 2\|\mathbf{a}\|\|\mathbf{b}\|\cos\theta. Expand LHS: ab2=(ab)(ab)=a22ab+b2\|\mathbf{a}-\mathbf{b}\|^2 = (\mathbf{a}-\mathbf{b})\cdot(\mathbf{a}-\mathbf{b}) = \|\mathbf{a}\|^2 - 2\,\mathbf{a}\cdot\mathbf{b} + \|\mathbf{b}\|^2. (2) Equate and cancel a2+b2\|\mathbf{a}\|^2+\|\mathbf{b}\|^2: 2ab=2abcosθab=abcosθ-2\,\mathbf{a}\cdot\mathbf{b} = -2\|\mathbf{a}\|\|\mathbf{b}\|\cos\theta \Rightarrow \mathbf{a}\cdot\mathbf{b} = \|\mathbf{a}\|\|\mathbf{b}\|\cos\theta. (2)

(b) ab=34+40=12\mathbf{a}\cdot\mathbf{b} = 3\cdot4 + 4\cdot0 = 12; b=4\|\mathbf{b}\| = 4. (1) Scalar projection =abb=124=3= \dfrac{\mathbf{a}\cdot\mathbf{b}}{\|\mathbf{b}\|} = \dfrac{12}{4} = 3. (1) Vector projection =abb2b=1216(4,0)=(3,0)= \dfrac{\mathbf{a}\cdot\mathbf{b}}{\|\mathbf{b}\|^2}\mathbf{b} = \dfrac{12}{16}(4,0) = (3,0). (2)

(c) cosθ=0\cos\theta = 0 iff θ=90°\theta = 90°; since ab=abcosθ\mathbf{a}\cdot\mathbf{b} = \|\mathbf{a}\|\|\mathbf{b}\|\cos\theta (with nonzero norms), the product is zero exactly when cosθ=0\cos\theta=0, i.e. vectors are perpendicular. (2)


Q2.

(a) det[2λ112λ]=(2λ)21=λ24λ+3=0\det\begin{bmatrix}2-\lambda & 1\\ 1 & 2-\lambda\end{bmatrix} = (2-\lambda)^2 - 1 = \lambda^2 - 4\lambda + 3 = 0. (2) Roots: (λ1)(λ3)=0λ1=3, λ2=1(\lambda-1)(\lambda-3)=0 \Rightarrow \lambda_1 = 3,\ \lambda_2 = 1. (2)

(b) For λ=3\lambda=3: (A3I)v=0v1+v2=0v=(1,1)(A-3I)\mathbf{v}=0 \Rightarrow -v_1+v_2=0 \Rightarrow v=(1,1), unit =12(1,1)=\tfrac{1}{\sqrt2}(1,1). (2) For λ=1\lambda=1: v1+v2=0v=(1,1)v_1+v_2=0 \Rightarrow v=(1,-1), unit =12(1,1)=\tfrac{1}{\sqrt2}(1,-1). (2)

(c) Q=12[1111]Q = \frac{1}{\sqrt2}\begin{bmatrix}1 & 1\\ 1 & -1\end{bmatrix}, Λ=[3001]\Lambda = \begin{bmatrix}3&0\\0&1\end{bmatrix}, and A=QΛQA = Q\Lambda Q^\top. (2) QQ is orthogonal because AA is symmetric ⇒ eigenvectors of distinct eigenvalues are orthogonal; normalized they form an orthonormal set so QQ=IQ^\top Q = I. (2)


Q3.

(a) (6)

import numpy as np
def power_iteration(A, iters=100):
    n = A.shape[0]
    v = np.random.rand(n)
    v = v / np.linalg.norm(v)
    for _ in range(iters):
        w = A @ v
        v = w / np.linalg.norm(w)        # normalize each step
    eigval = v @ (A @ v) / (v @ v)        # Rayleigh quotient
    return eigval, v

Marks: normalization (2), iteration/matvec (2), Rayleigh quotient (2).

(b) Expand the start vector in the eigenbasis v0=ciqiv_0 = \sum c_i q_i. Then Akv0=ciλikqi=λ1k(c1q1+i>1ci(λi/λ1)kqi)A^k v_0 = \sum c_i \lambda_i^k q_i = \lambda_1^k(c_1 q_1 + \sum_{i>1} c_i(\lambda_i/\lambda_1)^k q_i). Since λi/λ1<1|\lambda_i/\lambda_1|<1 for i>1i>1, all other terms vanish, leaving the direction of q1q_1. (2) Fails if λ1|\lambda_1| is not strictly dominant (e.g. λ1=λ2\lambda_1=-\lambda_2 or complex pair equal magnitude), or if c1=0c_1=0 (start vector orthogonal to dominant eigenvector). (2)


Q4.

(a) Rows R2R22R1R_2 \leftarrow R_2 - 2R_1, R3R33R1R_3 \leftarrow R_3 - 3R_1: [121100110011]\begin{bmatrix}1&2&1&|&1\\0&0&1&|&1\\0&0&1&|&1\end{bmatrix} Then R3R3R2R_3 \leftarrow R_3 - R_2: [121100110000]\begin{bmatrix}1&2&1&|&1\\0&0&1&|&1\\0&0&0&|&0\end{bmatrix} (4)

(b) Rank =2=2 (two nonzero pivot rows). (2) Null space: from echelon form, x3=0x_3=0 (from row 2 homogeneous), x1+2x2+x3=0x1=2x2x_1 + 2x_2 + x_3 = 0 \Rightarrow x_1 = -2x_2. Free variable x2x_2: null vector (2,1,0)(-2,1,0). Basis {(2,1,0)}\{(-2,1,0)\}. (2)

(c) Consistent (no 0=0=nonzero row). Particular: x3=1x_3=1, choose x2=0x1=1x3=0x_2=0 \Rightarrow x_1 = 1 - x_3 = 0, so xp=(0,0,1)x_p=(0,0,1). General: x=(0,0,1)+t(2,1,0)\mathbf{x} = (0,0,1) + t(-2,1,0). (2)


Q5.

(a) M=[2112]M = \begin{bmatrix}2 & 1\\ 1 & 2\end{bmatrix} (off-diagonals split the 2x1x22x_1x_2 term equally). (3)

(b) Eigenvalue test: from Q2, eigenvalues are 33 and 11, both >0>0 ⇒ positive definite. (2.5) Sylvester: leading minors D1=2>0D_1 = 2 > 0, D2=detM=41=3>0D_2 = \det M = 4-1 = 3 > 0 ⇒ positive definite. (2.5)

(c) A positive-definite Hessian at a critical point means the point is a strict local minimum (locally convex). (2)


Q6.

(a) A=UΣVA = U\Sigma V^\top with U,VU,V orthogonal, Σ\Sigma diagonal (nonneg singular values). VV^\top rotates/reflects input basis, Σ\Sigma scales along axes by singular values (unit sphere → axis-aligned ellipsoid), UU rotates the ellipsoid into output space. (4)

(b) AA=VΣUUΣV=VΣ2VA^\top A = V\Sigma^\top U^\top U \Sigma V^\top = V\Sigma^2 V^\top, an eigendecomposition. Hence eigenvalues of AAA^\top A are σi2\sigma_i^2, so singular values σi=λi(AA)\sigma_i = \sqrt{\lambda_i(A^\top A)} (nonnegative). (4)


[
  {"claim":"Q1b vector projection of (3,4) onto (4,0) is (3,0)","code":"a=Matrix([3,4]); b=Matrix([4,0]); proj=(a.dot(b)/b.dot(b))*b; result = proj==Matrix([3,0])"},
  {"claim":"Q2 eigenvalues of [[2,1],[1,2]] are 1 and 3","code":"A=Matrix([[2,1],[1,2]]); result = set(A.eigenvals().keys())=={1,3}"},
  {"claim":"Q4 rank of coefficient matrix is 2","code":"M=Matrix([[1,2,1],[2,4,3],[3,6,4]]); result = M.rank()==2"},
  {"claim":"Q4 null space basis vector (-2,1,0)","code":"M=Matrix([[1,2,1],[2,4,3],[3,6,4]]); ns=M.nullspace(); result = ns[0]== -2*Matrix([1,Rational(-1,2),0]) or ns[0].T*Matrix([1,2,1])==Matrix([0]) and (M*Matrix([-2,1,0])==Matrix([0,0,0]))"},
  {"claim":"Q5 M=[[2,1],[1,2]] is positive definite (both leading minors positive)","code":"M=Matrix([[2,1],[1,2]]); result = (M[0,0]>0) and (M.det()>0)"}
]