Interleaved — Phase 1

AI-ML interleaved practice

printable — key stays hidden on paper

Instructions. Solve each problem on its own. These problems deliberately jump between subtopics — before computing, identify which tool each problem needs. Show all work. Use \|\cdot\| notation for norms. Total: 50 marks.


1. (5 marks) Let u=(3,4)\mathbf{u} = (3, -4) and v=(1,2)\mathbf{v} = (1, 2). (a) Compute uv\mathbf{u}\cdot\mathbf{v}. (b) Find the angle θ\theta between them (in terms of arccos\arccos). (c) Find the scalar projection of u\mathbf{u} onto v\mathbf{v}.


2. (6 marks) For the matrix A=(210131012),A = \begin{pmatrix} 2 & 1 & 0 \\ 1 & 3 & 1 \\ 0 & 1 & 2 \end{pmatrix}, determine whether AA is symmetric, and whether AA is positive definite. Justify using the appropriate criterion.


3. (4 marks) Let x=(1,3,4,2)\mathbf{x} = (1, -3, 4, -2). Compute x1\|\mathbf{x}\|_1, x2\|\mathbf{x}\|_2, and x\|\mathbf{x}\|_\infty.


4. (6 marks) Let f(x,y)=x2y+sin(xy)f(x, y) = x^2 y + \sin(xy). Compute the gradient f\nabla f, and evaluate it at (1,0)(1, 0).


5. (5 marks) Given A=(1234),A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, compute det(A)\det(A), state whether AA is invertible, and if so compute A1A^{-1}.


6. (5 marks) Find all eigenvalues of B=(4123),B = \begin{pmatrix} 4 & 1 \\ 2 & 3 \end{pmatrix}, and give an eigenvector for the largest eigenvalue.


7. (5 marks) Determine the rank of C=(123246111)C = \begin{pmatrix} 1 & 2 & 3 \\ 2 & 4 & 6 \\ 1 & 1 & 1 \end{pmatrix} using Gaussian elimination, and state the dimension of its null space.


8. (4 marks) Let g(t)=(t2+1)e3tg(t) = (t^2 + 1)\,e^{3t}. Compute g(t)g'(t) using the appropriate differentiation rule.


9. (5 marks) Given AA is 3×43\times 4 and BB is 4×24 \times 2. State the dimensions of ABAB and of (AB)(AB)^\top. If vR2\mathbf{v}\in\mathbb{R}^2, is ABvAB\mathbf{v} defined, and what is its dimension? Also state tr\operatorname{tr} requirements: for which of ABAB or BABA is the trace defined?


10. (5 marks) Let f(x,y)=3x2+2xy+y2f(x,y) = 3x^2 + 2xy + y^2. Compute the Hessian matrix HH and state whether ff is convex.

Answer keyMark scheme & solutions

1. (Subtopic 1.1.3 — Dot product / projection / angle) (a) uv=3(1)+(4)(2)=38=5\mathbf{u}\cdot\mathbf{v} = 3(1) + (-4)(2) = 3 - 8 = -5. (b) u=5\|\mathbf{u}\| = 5, v=5\|\mathbf{v}\| = \sqrt{5}. cosθ=555=15\cos\theta = \dfrac{-5}{5\sqrt5} = \dfrac{-1}{\sqrt5}, so θ=arccos(1/5)116.6\theta = \arccos(-1/\sqrt5) \approx 116.6^\circ. (c) Scalar projection of u\mathbf u onto v\mathbf v =uvv=55=5= \dfrac{\mathbf u\cdot\mathbf v}{\|\mathbf v\|} = \dfrac{-5}{\sqrt5} = -\sqrt5. Why: the phrase "angle / projection" signals the dot-product toolkit, not norms alone.

2. (Subtopics 1.1.6 symmetric + 1.1.17 positive definite) A=AA = A^\top (mirror across diagonal) → symmetric. Positive definite test via leading principal minors: Δ1=2>0\Delta_1 = 2 > 0; Δ2=det(2113)=5>0\Delta_2 = \det\begin{pmatrix}2&1\\1&3\end{pmatrix} = 5 > 0; Δ3=detA\Delta_3 = \det A. detA=2(321)1(120)+0=2(5)2=8>0\det A = 2(3\cdot2 - 1) - 1(1\cdot2 - 0) + 0 = 2(5) - 2 = 8 > 0. All minors positive → positive definite. Why: symmetric structure is required before applying the Sylvester (minors) criterion — recognizing that ordering is the point.

3. (Subtopic 1.1.4 — norms) x1=1+3+4+2=10\|\mathbf x\|_1 = 1+3+4+2 = 10. x2=1+9+16+4=305.48\|\mathbf x\|_2 = \sqrt{1+9+16+4} = \sqrt{30}\approx 5.48. x=max(1,3,4,2)=4\|\mathbf x\|_\infty = \max(1,3,4,2) = 4. Why: three different norm definitions on the same vector — forces recall of each formula.

4. (Subtopic 1.2.4 gradient, using 1.2.3 partials) fx=2xy+ycos(xy)f_x = 2xy + y\cos(xy), fy=x2+xcos(xy)f_y = x^2 + x\cos(xy). f=(2xy+ycos(xy),  x2+xcos(xy))\nabla f = (2xy + y\cos(xy),\; x^2 + x\cos(xy)). At (1,0)(1,0): fx=0+0=0f_x = 0 + 0 = 0; fy=1+1cos(0)=1+1=2f_y = 1 + 1\cdot\cos(0) = 1 + 1 = 2. So f(1,0)=(0,2)\nabla f(1,0) = (0, 2). Why: gradient = vector of partials; chain rule inside sin(xy)\sin(xy).

5. (Subtopics 1.1.9 determinant + 1.1.8 inverse) detA=1423=46=20\det A = 1\cdot4 - 2\cdot3 = 4 - 6 = -2 \neq 0 → invertible. A1=12(4231)=(211.50.5)A^{-1} = \dfrac{1}{-2}\begin{pmatrix} 4 & -2 \\ -3 & 1 \end{pmatrix} = \begin{pmatrix} -2 & 1 \\ 1.5 & -0.5 \end{pmatrix}. Why: nonzero determinant is the invertibility condition; then the 2×2 adjugate formula.

6. (Subtopic 1.1.13 — eigenvalues/eigenvectors) det(BλI)=(4λ)(3λ)2=λ27λ+10=(λ5)(λ2)\det(B - \lambda I) = (4-\lambda)(3-\lambda) - 2 = \lambda^2 -7\lambda + 10 = (\lambda-5)(\lambda-2). Eigenvalues λ=5,2\lambda = 5, 2. Largest is 55: (B5I)x=(1122)x=0x1=x2(B-5I)\mathbf x = \begin{pmatrix}-1&1\\2&-2\end{pmatrix}\mathbf x = 0 \Rightarrow x_1 = x_2. Eigenvector (1,1)(1,1). Why: characteristic polynomial, not decomposition — problem only asks eigenvalues/vectors.

7. (Subtopics 1.1.10 rank/null space + 1.1.12 Gaussian elimination) Row-reduce: R2R22R1=(0,0,0)R_2 \to R_2 - 2R_1 = (0,0,0); R3R3R1=(0,1,2)R_3 \to R_3 - R_1 = (0,-1,-2). Rows: (1,2,3),(0,1,2),(0,0,0)(1,2,3),(0,-1,-2),(0,0,0) → 2 pivots → rank 2. Nullity =nrank=32=1= n - \text{rank} = 3 - 2 = 1. Why: elimination reveals rank; rank–nullity gives null-space dimension.

8. (Subtopic 1.2.2 — product + chain rule) g(t)=(2t)e3t+(t2+1)(3e3t)=e3t(2t+3t2+3)=e3t(3t2+2t+3)g'(t) = (2t)e^{3t} + (t^2+1)(3e^{3t}) = e^{3t}(2t + 3t^2 + 3) = e^{3t}(3t^2 + 2t + 3). Why: product rule with a chain-rule factor ddte3t=3e3t\frac{d}{dt}e^{3t}=3e^{3t}.

9. (Subtopics 1.1.5 matrix mult dims + 1.1.7 transpose + 1.1.16 trace) A3×4B4×2=(AB)3×2A_{3\times4}B_{4\times2} = (AB)_{3\times2}. (AB)(AB)^\top is 2×32\times3. ABvAB\mathbf v: (3×2)(2×1)=3×1(3\times2)(2\times1) = 3\times1 vector — defined. Trace requires a square matrix. ABAB is 3×23\times2 (not square) → trace undefined. BABA is 4×44\times4 (square) → tr(BA)\operatorname{tr}(BA) defined. Why: dimensional-compatibility bookkeeping plus square-only trace rule.

10. (Subtopics 1.2.6 Hessian + 1.1.17 relation to PD/convexity) fx=6x+2yf_x = 6x + 2y, fy=2x+2yf_y = 2x + 2y. H=(fxxfxyfyxfyy)=(6222)H = \begin{pmatrix} f_{xx} & f_{xy} \\ f_{yx} & f_{yy}\end{pmatrix} = \begin{pmatrix} 6 & 2 \\ 2 & 2 \end{pmatrix}. Minors: 6>06>0, det=124=8>0\det = 12 - 4 = 8 > 0 → PD → ff is convex (strictly). Why: connects second-derivative Hessian to positive-definiteness convexity test.

[
  {"claim":"Problem 2: det A = 8 and A positive definite (all leading minors positive)","code":"import sympy as sp\nA=sp.Matrix([[2,1,0],[1,3,1],[0,1,2]])\nm1=A[0,0]; m2=A[:2,:2].det(); m3=A.det()\nresult=(m3==8) and all(x>0 for x in [m1,m2,m3])"},
  {"claim":"Problem 6: eigenvalues of B are {2,5}","code":"import sympy as sp\nB=sp.Matrix([[4,1],[2,3]])\nresult=set(B.eigenvals().keys())=={sp.Integer(2),sp.Integer(5)}"},
  {"claim":"Problem 10: Hessian is [[6,2],[2,2]] and positive definite","code":"import sympy as sp\nx,y=sp.symbols('x y')\nf=3*x**2+2*x*y+y**2\nH=sp.hessian(f,(x,y))\nmz=H[0,0]>0 and H.det()>0\nresult=(H==sp.Matrix([[6,2],[2,2]])) and mz"}
]