Practice / Linear algebra

Linear transformations and change of basis

Ten problems on linear maps and their matrices: a matrix built from the images of e₁ and e₂, a test for linearity, rotations and reflections composed in both orders, a projection with its kernel, image and rank–nullity count, coordinates in a new basis, a reflection across y = 2x built from diag(1, −1), the matrix of a map in a new basis two ways, what similar matrices share, the determinant as an area scale and an orientation, and PCA coordinates and whitening in an orthonormal basis, with worked solutions and the mistakes of writing the images as rows, composing in reading order, multiplying by P instead of P⁻¹, using Pᵀ for P⁻¹ when the basis is not orthonormal and treating x ↦ Ax + b as linear.

Before you start

A matrix is a linear map written down in a particular basis. Change the basis and the same map gets a different matrix, sometimes a much simpler one: a reflection across a slanted line becomes diag⁡(1,−1)\operatorname{diag}(1, -1), and a covariance matrix becomes diagonal in the coordinates PCA picks. These ten problems build the matrix of a map from what it does to the standard basis, test whether a map is linear at all, compose maps in the right order, take a projection apart into its kernel and image, and then change basis, first for a single vector and then for a whole map. They end with the determinant as an area scale and with PCA coordinates and whitening. The five mistakes at the end are the ones that still produce a matrix: the images written as rows, a composition multiplied in reading order, coordinates found with PP instead of P−1P^{-1}, P⊤P^\top used as P−1P^{-1} for a basis that is not orthonormal, and an affine map treated as linear.

  • Vectors are columns; (3,−2)⊤(3, -2)^\top is the column with entries 33 and −2-2, written on one line to save space. e1=(1,0)⊤e_1 = (1, 0)^\top and e2=(0,1)⊤e_2 = (0, 1)^\top are the standard basis of R2\mathbb{R}^2.
  • A map T:Rn→RmT: \mathbb{R}^n \to \mathbb{R}^m is linear when T(u+v)=T(u)+T(v)T(u + v) = T(u) + T(v) and T(cu)=cT(u)T(cu) = cT(u) for all vectors u,vu, v and numbers cc. Then T(x)=AxT(x) = Ax for the m×nm\times n matrix AA whose column jj is T(ej)T(e_j).
  • ABAB means “apply BB, then AA”: (AB)x=A(Bx)(AB)x = A(Bx).
  • The kernel of AA is {x:Ax=0}\{x : Ax = 0\}, the image is {Ax}\{Ax\}, and for AA with nn columns, dim⁡ker⁡A+rank⁡A=n\dim\ker A + \operatorname{rank}A = n (rank–nullity).
  • A basis B={b1,…,bn}B = \{b_1, \ldots, b_n\} of Rn\mathbb{R}^n has basis matrix P=[ b1  ⋯  bn ]P = [\,b_1 \;\cdots\; b_n\,], with the basis vectors as columns. The coordinates [v]B=c[v]_B = c are the numbers with v=c1b1+⋯+cnbnv = c_1b_1 + \cdots + c_nb_n, that is Pc=vPc = v, so [v]B=P−1v[v]_B = P^{-1}v.
  • The matrix of a linear map T(x)=AxT(x) = Ax in the basis BB is [T]B=P−1AP[T]_B = P^{-1}AP: its column jj is [T(bj)]B[T(b_j)]_B. Matrices AA and P−1APP^{-1}AP are called similar.
  • A basis is orthonormal when its vectors have length 11 and are pairwise orthogonal; then P⊤P=IP^\top P = I, so P−1=P⊤P^{-1} = P^\top.
  • For 2×22\times2 matrices, [abcd]−1=1ad−bc[d−b−ca]\begin{bmatrix}a&b\\c&d\end{bmatrix}^{-1} = \dfrac{1}{ad-bc}\begin{bmatrix}d&-b\\-c&a\end{bmatrix} when ad−bc≠0ad - bc \neq 0.

Builds on: Vectors in 3-D: dot and cross products, lines and planes, Gaussian elimination, inverses and determinants by hand

Problems

  1. ·

    A linear map T:R2→R2T: \mathbb{R}^2 \to \mathbb{R}^2 sends e1e_1 to (2,1)⊤(2, 1)^\top and e2e_2 to (−1,3)⊤(-1, 3)^\top. Find its matrix AA and T((3,−2)⊤)T\big((3, -2)^\top\big).

  2. ·

    Which of these maps R2→R2\mathbb{R}^2 \to \mathbb{R}^2 are linear? For each linear one, give its matrix.

    T1(x,y)=(x+2y, 3x−y+1)T2(x,y)=(∣x∣, y)T3(x,y)=(2x−y, x)\begin{aligned} T_1(x, y) &= (x + 2y,\ 3x - y + 1)\\ T_2(x, y) &= (|x|,\ y)\\ T_3(x, y) &= (2x - y,\ x) \end{aligned}
  3. ··

    Let RR rotate the plane by 90∘90^\circ counterclockwise and FF reflect it across the xx-axis. Find RR, FF, RFRF and FRFR, and describe each product geometrically. Which one is “reflect first, then rotate”?

  4. ··

    Let Π\Pi be the orthogonal projection onto the line through u=(1,2)⊤u = (1, 2)^\top, so Πx=u⊤xu⊤u u\Pi x = \dfrac{u^\top x}{u^\top u}\,u. Find the matrix of Π\Pi, its kernel and image, and check rank–nullity and Π2=Π\Pi^2 = \Pi.

  5. ··

    Let B={b1,b2}B = \{b_1, b_2\} with b1=(1,1)⊤b_1 = (1, 1)^\top and b2=(1,2)⊤b_2 = (1, 2)^\top. Find the coordinates [v]B[v]_B of v=(3,5)⊤v = (3, 5)^\top, and check them.

  6. ···

    Find the matrix, in the standard basis, of the reflection TT across the line y=2xy = 2x. Use a basis in which TT is diag⁡(1,−1)\operatorname{diag}(1, -1).

  7. ···

    Let A=[1203]A = \begin{bmatrix}1&2\\0&3\end{bmatrix} and use the basis BB of Problem 5. Find [T]B[T]_B for T(x)=AxT(x) = Ax in two ways: column by column from [T(bj)]B[T(b_j)]_B, and as P−1APP^{-1}AP.

  8. ··

    Show that similar matrices AA and P−1APP^{-1}AP have the same characteristic polynomial, and hence the same eigenvalues, trace and determinant. Then show that II and N=[1101]N = \begin{bmatrix}1&1\\0&1\end{bmatrix} have the same trace and determinant but are not similar.

  9. ··

    Let A=[1321]A = \begin{bmatrix}1&3\\2&1\end{bmatrix}. What is the area of the image of the triangle with vertices (0,0)(0, 0), (1,0)(1, 0) and (0,1)(0, 1)? Does AA keep or reverse orientation? What is the area scale factor of RARA, with RR the rotation of Problem 3?

  10. ···

    A two-feature data set has covariance Σ=[5222]\Sigma = \begin{bmatrix}5&2\\2&2\end{bmatrix}. Its unit eigenvectors are q1=(2,1)⊤/5q_1 = (2, 1)^\top/\sqrt5 and q2=(1,−2)⊤/5q_2 = (1, -2)^\top/\sqrt5. With Q=[ q1  q2 ]Q = [\,q_1\; q_2\,], find the PCA coordinates c=[x]Qc = [x]_Q of x=(1,3)⊤x = (1, 3)^\top, the covariance of the data in those coordinates, and the whitened coordinates z=Λ−1/2cz = \Lambda^{-1/2}c, where Λ\Lambda is the diagonal matrix of eigenvalues.

Worked solutions

Problem 1

A linear map T:R2→R2T: \mathbb{R}^2 \to \mathbb{R}^2 sends e1e_1 to (2,1)⊤(2, 1)^\top and e2e_2 to (−1,3)⊤(-1, 3)^\top. Find its matrix AA and T((3,−2)⊤)T\big((3, -2)^\top\big).

  1. (3,−2)⊤=3e1−2e2(3, -2)^\top = 3e_1 - 2e_2.Every vector is a combination of the standard basis, with its entries as the coefficients.
  2. T((3,−2)⊤)=3T(e1)−2T(e2)T\big((3, -2)^\top\big) = 3T(e_1) - 2T(e_2).Linearity: TT of a combination is the same combination of the images.
  3. =3(2,1)⊤−2(−1,3)⊤=(8,−3)⊤= 3(2, 1)^\top - 2(-1, 3)^\top = (8, -3)^\top.(6+2, 3−6)(6 + 2,\ 3 - 6).
  4. A=[2−113]A = \begin{bmatrix}2&-1\\1&3\end{bmatrix}.Column jj is T(ej)T(e_j), so AejAe_j picks out exactly that image.
  5. A=[2−113]A = \begin{bmatrix}2&-1\\1&3\end{bmatrix}; T((3,−2)⊤)=(8,−3)⊤T\big((3, -2)^\top\big) = (8, -3)^\topCheck: A(3,−2)⊤A(3, -2)^\top has rows 2⋅3+(−1)(−2)=82\cdot3 + (-1)(-2) = 8 and 1⋅3+3(−2)=−31\cdot3 + 3(-2) = -3. Two images determine the whole map: that is what linearity buys.

Problem 2

Which of these maps R2→R2\mathbb{R}^2 \to \mathbb{R}^2 are linear? For each linear one, give its matrix.

T1(x,y)=(x+2y, 3x−y+1)T2(x,y)=(∣x∣, y)T3(x,y)=(2x−y, x)\begin{aligned} T_1(x, y) &= (x + 2y,\ 3x - y + 1)\\ T_2(x, y) &= (|x|,\ y)\\ T_3(x, y) &= (2x - y,\ x) \end{aligned}
  1. T1(0,0)=(0,1)T_1(0, 0) = (0, 1).A linear map sends 00 to 00, because T(0)=T(0⋅0)=0⋅T(0)=0T(0) = T(0\cdot0) = 0\cdot T(0) = 0. T1T_1 fails, because of the constant +1+1.
  2. T2(−1,0)=(1,0)T_2(-1, 0) = (1, 0) but −T2(1,0)=(−1,0)-T_2(1, 0) = (-1, 0).Scaling by c=−1c = -1 is not preserved, so T2T_2 is not linear, even though T2(0)=0T_2(0) = 0.
  3. T3T_3 is linear: each output entry is a combination of xx and yy with no constant.Then both rules hold entry by entry.
  4. T3(e1)=(2,1)⊤T_3(e_1) = (2, 1)^\top, T3(e2)=(−1,0)⊤T_3(e_2) = (-1, 0)^\top.Read off with (x,y)=(1,0)(x, y) = (1, 0) and (0,1)(0, 1).
  5. Only T3T_3 is linear, with matrix [2−110]\begin{bmatrix}2&-1\\1&0\end{bmatrix}; T1T_1 is affine, not linear, and T2T_2 is not linearT1(x)=Ax+bT_1(x) = Ax + b with b=(0,1)⊤b = (0, 1)^\top. A dense layer Wx+bWx + b is affine in the same way; it becomes linear only with b=0b = 0, or after appending a constant 11 to xx.

Problem 3

Let RR rotate the plane by 90∘90^\circ counterclockwise and FF reflect it across the xx-axis. Find RR, FF, RFRF and FRFR, and describe each product geometrically. Which one is “reflect first, then rotate”?

  1. R=[0−110]R = \begin{bmatrix}0&-1\\1&0\end{bmatrix}.R(e1)=e2=(0,1)⊤R(e_1) = e_2 = (0, 1)^\top and R(e2)=−e1=(−1,0)⊤R(e_2) = -e_1 = (-1, 0)^\top are its columns.
  2. F=[100−1]F = \begin{bmatrix}1&0\\0&-1\end{bmatrix}.FF keeps e1e_1 and sends e2e_2 to −e2-e_2.
  3. RF=[0110]RF = \begin{bmatrix}0&1\\1&0\end{bmatrix}.Row times column; or by columns: RFe1=Re1=e2RF e_1 = R e_1 = e_2 and RFe2=R(−e2)=e1RF e_2 = R(-e_2) = e_1.
  4. RFRF swaps xx and yy: it is the reflection across y=xy = x.RF(x,y)⊤=(y,x)⊤RF(x, y)^\top = (y, x)^\top.
  5. FR=[0−1−10]FR = \begin{bmatrix}0&-1\\-1&0\end{bmatrix}, so FR(x,y)⊤=(−y,−x)⊤FR(x, y)^\top = (-y, -x)^\top: the reflection across y=−xy = -x.FRe1=Fe2=−e2FRe_1 = F e_2 = -e_2 and FRe2=F(−e1)=−e1FRe_2 = F(-e_1) = -e_1.
  6. RF=[0110]RF = \begin{bmatrix}0&1\\1&0\end{bmatrix}, reflection across y=xy = x, is “reflect, then rotate”; FR=[0−1−10]FR = \begin{bmatrix}0&-1\\-1&0\end{bmatrix}, reflection across y=−xy = -x, is “rotate, then reflect”(RF)x=R(Fx)(RF)x = R(Fx): the factor next to xx acts first. Matrix products are composed right to left, and RF≠FRRF \neq FR. Both have determinant −1-1, as a rotation times a reflection must.

Problem 4

Let Π\Pi be the orthogonal projection onto the line through u=(1,2)⊤u = (1, 2)^\top, so Πx=u⊤xu⊤u u\Pi x = \dfrac{u^\top x}{u^\top u}\,u. Find the matrix of Π\Pi, its kernel and image, and check rank–nullity and Π2=Π\Pi^2 = \Pi.

  1. Πx=u(u⊤x)u⊤u=uu⊤u⊤u x\Pi x = \dfrac{u(u^\top x)}{u^\top u} = \dfrac{uu^\top}{u^\top u}\,x.A scalar times a vector can be written with the scalar on the right, and u(u⊤x)=(uu⊤)xu(u^\top x) = (uu^\top)x.
  2. Π=15[1224]\Pi = \tfrac15\begin{bmatrix}1&2\\2&4\end{bmatrix}.u⊤u=1+4=5u^\top u = 1 + 4 = 5 and uu⊤uu^\top has entries uiuju_iu_j.
  3. ker⁡Π=span⁡{(2,−1)⊤}\ker\Pi = \operatorname{span}\{(2, -1)^\top\}.Πx=0\Pi x = 0 exactly when u⊤x=x1+2x2=0u^\top x = x_1 + 2x_2 = 0: the vectors orthogonal to uu.
  4. im⁡Π=span⁡{u}\operatorname{im}\Pi = \operatorname{span}\{u\}, so rank⁡Π=1\operatorname{rank}\Pi = 1.Every output is a multiple of uu, and Πu=u\Pi u = u, so every multiple is reached.
  5. 1+1=21 + 1 = 2, the number of columns.Rank–nullity: dim⁡ker⁡Π+rank⁡Π=n\dim\ker\Pi + \operatorname{rank}\Pi = n.
  6. Π2=u(u⊤u)u⊤(u⊤u)2=uu⊤u⊤u=Π\Pi^2 = \dfrac{u(u^\top u)u^\top}{(u^\top u)^2} = \dfrac{uu^\top}{u^\top u} = \Pi.u⊤uu^\top u is a number and cancels once. Projecting a second time changes nothing.
  7. Π=15[1224]\Pi = \tfrac15\begin{bmatrix}1&2\\2&4\end{bmatrix}; ker⁡Π=span⁡{(2,−1)⊤}\ker\Pi = \operatorname{span}\{(2, -1)^\top\}; im⁡Π=span⁡{(1,2)⊤}\operatorname{im}\Pi = \operatorname{span}\{(1, 2)^\top\}; 1+1=21 + 1 = 2; Π2=Π\Pi^2 = \Pidet⁡Π=(4−4)/25=0\det\Pi = (4 - 4)/25 = 0: a projection that loses a direction squashes area to zero, and cannot be undone.

Problem 5

Let B={b1,b2}B = \{b_1, b_2\} with b1=(1,1)⊤b_1 = (1, 1)^\top and b2=(1,2)⊤b_2 = (1, 2)^\top. Find the coordinates [v]B[v]_B of v=(3,5)⊤v = (3, 5)^\top, and check them.

  1. P=[1112]P = \begin{bmatrix}1&1\\1&2\end{bmatrix}.The basis vectors are the columns.
  2. det⁡P=2−1=1\det P = 2 - 1 = 1, so P−1=[2−1−11]P^{-1} = \begin{bmatrix}2&-1\\-1&1\end{bmatrix}.The 2×22\times2 inverse, with nothing to divide by. det⁡P≠0\det P \neq 0, so b1,b2b_1, b_2 really are a basis.
  3. [v]B=P−1v=(2⋅3−5, −3+5)⊤=(1,2)⊤[v]_B = P^{-1}v = (2\cdot3 - 5,\ -3 + 5)^\top = (1, 2)^\top.[v]B[v]_B solves Pc=vPc = v.
  4. 1⋅b1+2⋅b2=(1+2, 1+4)⊤=(3,5)⊤1\cdot b_1 + 2\cdot b_2 = (1 + 2,\ 1 + 4)^\top = (3, 5)^\top.The check multiplies by PP, the reverse direction.
  5. [v]B=(1,2)⊤[v]_B = (1, 2)^\top: v=b1+2b2v = b_1 + 2b_2PP turns BB-coordinates into standard ones; P−1P^{-1} goes the other way. In the standard basis the coordinates of vv are its entries, (3,5)(3, 5); in BB the same vector is (1,2)(1, 2).

Problem 6

Find the matrix, in the standard basis, of the reflection TT across the line y=2xy = 2x. Use a basis in which TT is diag⁡(1,−1)\operatorname{diag}(1, -1).

  1. Take b1=(1,2)⊤b_1 = (1, 2)^\top on the line and b2=(−2,1)⊤b_2 = (-2, 1)^\top perpendicular to it.b1⊤b2=−2+2=0b_1^\top b_2 = -2 + 2 = 0. The reflection keeps the line and flips the perpendicular direction.
  2. T(b1)=b1T(b_1) = b_1 and T(b2)=−b2T(b_2) = -b_2, so [T]B=diag⁡(1,−1)=D[T]_B = \operatorname{diag}(1, -1) = D.Column jj of [T]B[T]_B is [T(bj)]B[T(b_j)]_B: here (1,0)⊤(1, 0)^\top and (0,−1)⊤(0, -1)^\top.
  3. A=PDP−1A = PDP^{-1} with P=[1−221]P = \begin{bmatrix}1&-2\\2&1\end{bmatrix}.[T]B=P−1AP[T]_B = P^{-1}AP, solved for AA: multiply by PP on the left and P−1P^{-1} on the right.
  4. det⁡P=1+4=5\det P = 1 + 4 = 5, so P−1=15[12−21]P^{-1} = \tfrac15\begin{bmatrix}1&2\\-2&1\end{bmatrix}.The 2×22\times2 inverse. The columns of PP are orthogonal but have length 5\sqrt5, so P−1=15P⊤P^{-1} = \tfrac15P^\top, not P⊤P^\top.
  5. PD=[122−1]PD = \begin{bmatrix}1&2\\2&-1\end{bmatrix}.DD on the right scales column 22 of PP by −1-1.
  6. PDP−1=15[1−42+22+24−1]PDP^{-1} = \tfrac15\begin{bmatrix}1 - 4&2 + 2\\2 + 2&4 - 1\end{bmatrix}.Row times column with [12−21]\begin{bmatrix}1&2\\-2&1\end{bmatrix}, then the 15\tfrac15.
  7. A=15[−3443]A = \tfrac15\begin{bmatrix}-3&4\\4&3\end{bmatrix}Checks: A(1,2)⊤=15(5,10)⊤=(1,2)⊤A(1, 2)^\top = \tfrac15(5, 10)^\top = (1, 2)^\top, A(−2,1)⊤=(2,−1)⊤A(-2, 1)^\top = (2, -1)^\top, A2=IA^2 = I and det⁡A=−1\det A = -1. It matches the formula for the reflection across a line at angle φ\varphi, with cos⁡2φ=−35\cos2\varphi = -\tfrac35 and sin⁡2φ=45\sin2\varphi = \tfrac45 when tan⁡φ=2\tan\varphi = 2.

Problem 7

Let A=[1203]A = \begin{bmatrix}1&2\\0&3\end{bmatrix} and use the basis BB of Problem 5. Find [T]B[T]_B for T(x)=AxT(x) = Ax in two ways: column by column from [T(bj)]B[T(b_j)]_B, and as P−1APP^{-1}AP.

  1. T(b1)=A(1,1)⊤=(3,3)⊤=3b1+0b2T(b_1) = A(1, 1)^\top = (3, 3)^\top = 3b_1 + 0b_2.So column 11 of [T]B[T]_B is (3,0)⊤(3, 0)^\top. b1b_1 happens to be an eigenvector of AA.
  2. T(b2)=A(1,2)⊤=(5,6)⊤T(b_2) = A(1, 2)^\top = (5, 6)^\top.Row times column: 1+41 + 4 and 0+60 + 6.
  3. [T(b2)]B=P−1(5,6)⊤=(10−6, −5+6)⊤=(4,1)⊤[T(b_2)]_B = P^{-1}(5, 6)^\top = (10 - 6,\ -5 + 6)^\top = (4, 1)^\top.P−1P^{-1} from Problem 5. Check: 4b1+b2=(5,6)⊤4b_1 + b_2 = (5, 6)^\top.
  4. AP=[3536]AP = \begin{bmatrix}3&5\\3&6\end{bmatrix}.Its columns are T(b1)T(b_1) and T(b2)T(b_2), from steps 1 and 2.
  5. P−1(AP)=[6−310−6−3+3−5+6]P^{-1}(AP) = \begin{bmatrix}6 - 3&10 - 6\\-3 + 3&-5 + 6\end{bmatrix}.Row times column with P−1=[2−1−11]P^{-1} = \begin{bmatrix}2&-1\\-1&1\end{bmatrix}; this applies P−1P^{-1} to each column of APAP, which is step 3 done for both columns at once.
  6. [T]B=[3401][T]_B = \begin{bmatrix}3&4\\0&1\end{bmatrix} both waysBoth AA and [T]B[T]_B have trace 44 and determinant 33, so the same eigenvalues 11 and 33: they are one map written in two bases. Read right to left, P−1APP^{-1}AP says: turn BB-coordinates into standard ones (PP), apply the map (AA), turn the result back into BB-coordinates (P−1P^{-1}).

Problem 8

Show that similar matrices AA and P−1APP^{-1}AP have the same characteristic polynomial, and hence the same eigenvalues, trace and determinant. Then show that II and N=[1101]N = \begin{bmatrix}1&1\\0&1\end{bmatrix} have the same trace and determinant but are not similar.

  1. P−1AP−λI=P−1(A−λI)PP^{-1}AP - \lambda I = P^{-1}(A - \lambda I)P.λI=λP−1P=P−1(λI)P\lambda I = \lambda P^{-1}P = P^{-1}(\lambda I)P, then factor.
  2. det⁡(P−1(A−λI)P)=det⁡P−1 det⁡(A−λI) det⁡P=det⁡(A−λI)\det\big(P^{-1}(A - \lambda I)P\big) = \det P^{-1}\,\det(A - \lambda I)\,\det P = \det(A - \lambda I).det⁡\det of a product is the product of the det⁡\dets, and det⁡P−1=1/det⁡P\det P^{-1} = 1/\det P.
  3. The eigenvalues are the roots of the characteristic polynomial, and for a 2×22\times2 matrix it is λ2−(tr⁡A)λ+det⁡A\lambda^2 - (\operatorname{tr}A)\lambda + \det A.So equal polynomials mean equal eigenvalues, trace and determinant; for n×nn\times n the trace and determinant are still coefficients of the polynomial.
  4. tr⁡I=tr⁡N=2\operatorname{tr}I = \operatorname{tr}N = 2 and det⁡I=det⁡N=1\det I = \det N = 1.Both are triangular with diagonal (1,1)(1, 1).
  5. P−1IP=P−1P=IP^{-1}IP = P^{-1}P = I for every invertible PP.So the only matrix similar to II is II itself, and N≠IN \neq I.
  6. det⁡(P−1AP−λI)=det⁡(A−λI)\det(P^{-1}AP - \lambda I) = \det(A - \lambda I), so eigenvalues, trace and determinant are shared; II and NN share them but are not similar, because II is similar only to itselfEqual invariants are necessary for similarity, not sufficient. NN is the shear of the eigenvalues page: it has one eigenvector direction where II has two.

Problem 9

Let A=[1321]A = \begin{bmatrix}1&3\\2&1\end{bmatrix}. What is the area of the image of the triangle with vertices (0,0)(0, 0), (1,0)(1, 0) and (0,1)(0, 1)? Does AA keep or reverse orientation? What is the area scale factor of RARA, with RR the rotation of Problem 3?

  1. det⁡A=1−6=−5\det A = 1 - 6 = -5.ad−bcad - bc.
  2. A linear map scales every area by ∣det⁡A∣|\det A|.It sends the unit square to the parallelogram spanned by its columns, whose area is ∣det⁡A∣|\det A|, and every region is a limit of small squares.
  3. The image triangle has area 5⋅12=525\cdot\tfrac12 = \tfrac52.The original triangle has area 12\tfrac12. Its image has vertices (0,0)(0, 0), (1,2)(1, 2) and (3,1)(3, 1), and 12∣1⋅1−3⋅2∣=52\tfrac12|1\cdot1 - 3\cdot2| = \tfrac52 directly.
  4. det⁡A<0\det A < 0, so AA reverses orientation.Going (0,0)→(1,0)→(0,1)(0, 0) \to (1, 0) \to (0, 1) is counterclockwise; the image path (0,0)→(1,2)→(3,1)(0, 0) \to (1, 2) \to (3, 1) turns clockwise.
  5. det⁡(RA)=det⁡R det⁡A=1⋅(−5)=−5\det(RA) = \det R\,\det A = 1\cdot(-5) = -5.A rotation has determinant 11: it keeps both area and orientation.
  6. Area 52\tfrac52; AA reverses orientation (det⁡A=−5\det A = -5); RARA also scales areas by 55 and reverses orientationThe sign of the determinant records orientation and its size records the area scale. In a normalizing flow, log⁡∣det⁡∣\log|\det| of each layer's Jacobian is exactly this area (volume) scale, and it enters the log-likelihood.

Problem 10

A two-feature data set has covariance Σ=[5222]\Sigma = \begin{bmatrix}5&2\\2&2\end{bmatrix}. Its unit eigenvectors are q1=(2,1)⊤/5q_1 = (2, 1)^\top/\sqrt5 and q2=(1,−2)⊤/5q_2 = (1, -2)^\top/\sqrt5. With Q=[ q1  q2 ]Q = [\,q_1\; q_2\,], find the PCA coordinates c=[x]Qc = [x]_Q of x=(1,3)⊤x = (1, 3)^\top, the covariance of the data in those coordinates, and the whitened coordinates z=Λ−1/2cz = \Lambda^{-1/2}c, where Λ\Lambda is the diagonal matrix of eigenvalues.

  1. Σq1=(12,6)⊤/5=6q1\Sigma q_1 = (12, 6)^\top/\sqrt5 = 6q_1 and Σq2=(1,−2)⊤/5=q2\Sigma q_2 = (1, -2)^\top/\sqrt5 = q_2, so Λ=diag⁡(6,1)\Lambda = \operatorname{diag}(6, 1).Check the eigenvectors before using them: (10+2, 4+2)(10 + 2,\ 4 + 2) and (5−4, 2−4)(5 - 4,\ 2 - 4).
  2. q1⊤q2=(2−2)/5=0q_1^\top q_2 = (2 - 2)/5 = 0 and q1⊤q1=q2⊤q2=1q_1^\top q_1 = q_2^\top q_2 = 1, so Q−1=Q⊤Q^{-1} = Q^\top.The basis is orthonormal, so no inverse needs computing.
  3. c=Q⊤x=((2+3)/5, (1−6)/5)⊤=(5,−5)⊤c = Q^\top x = \big((2 + 3)/\sqrt5,\ (1 - 6)/\sqrt5\big)^\top = (\sqrt5, -\sqrt5)^\top.Each coordinate is a dot product qj⊤xq_j^\top x. Check: ∥c∥2=10=∥x∥2\|c\|^2 = 10 = \|x\|^2, since an orthonormal change of basis keeps lengths.
  4. In QQ-coordinates the data are c=Q⊤xc = Q^\top x, with covariance Q⊤ΣQQ^\top\Sigma Q.For a linear map MM, Cov⁡(Mx)=MΣM⊤\operatorname{Cov}(Mx) = M\Sigma M^\top; here M=Q⊤M = Q^\top.
  5. Q⊤ΣQ=Q−1ΣQ=Λ=diag⁡(6,1)Q^\top\Sigma Q = Q^{-1}\Sigma Q = \Lambda = \operatorname{diag}(6, 1).This is [T]Q[T]_Q for T(x)=ΣxT(x) = \Sigma x: in the eigenvector basis the matrix is diagonal.
  6. z=Λ−1/2c=(5/6, −5)⊤≈(0.913,−2.236)⊤z = \Lambda^{-1/2}c = (\sqrt5/\sqrt6,\ -\sqrt5)^\top \approx (0.913, -2.236)^\top.Divide coordinate jj by λj\sqrt{\lambda_j}; its covariance is Λ−1/2ΛΛ−1/2=I\Lambda^{-1/2}\Lambda\Lambda^{-1/2} = I.
  7. c=(5,−5)⊤c = (\sqrt5, -\sqrt5)^\top; covariance diag⁡(6,1)\operatorname{diag}(6, 1), uncorrelated; z=(5/6,−5)⊤≈(0.913,−2.236)⊤z = (\sqrt{5/6}, -\sqrt5)^\top \approx (0.913, -2.236)^\top with covariance IIPCA is a change to an orthonormal basis that diagonalizes Σ\Sigma; whitening then rescales each new axis to variance 11. The rescaling is not orthogonal, so ∥z∥≠∥x∥\|z\| \neq \|x\|.

Where this goes wrong

1. Images written as rows

The images T(e1)T(e_1) and T(e2)T(e_2) are usually listed one after the other, and it is natural to write them into the matrix the same way, line by line.

  1. T(e1)=(2,1)⊤T(e_1) = (2, 1)^\top, T(e2)=(−1,3)⊤T(e_2) = (-1, 3)^\topRight so far: Problem 1.
  2. “Write the first image in the first row and the second in the second.”The habit that causes the mistake: filling a matrix row by row, the way it is read.
  3. A=[21−13]A = \begin{bmatrix}2&1\\-1&3\end{bmatrix}, so T((3,−2)⊤)=(4,−9)⊤T\big((3, -2)^\top\big) = (4, -9)^\topThat is A⊤A^\top. Ae1Ae_1 is the first column of AA, so the images must be columns; the right answer is (8,−3)⊤(8, -3)^\top. The check is cheap: multiply the matrix by e1e_1 and see whether T(e1)T(e_1) comes out.

2. Composing in reading order

“Reflect, then rotate” names the reflection first, and the product is easy to write in the same order.

  1. R=[0−110]R = \begin{bmatrix}0&-1\\1&0\end{bmatrix} and F=[100−1]F = \begin{bmatrix}1&0\\0&-1\end{bmatrix}Right so far: Problem 3.
  2. “Reflect, then rotate: FF then RR, so FRFR.”The habit that causes the mistake: writing the factors left to right in the order they happen.
  3. “Reflect, then rotate” =FR= FR, which sends e1e_1 to (0,−1)⊤(0, -1)^\top(FR)x=F(Rx)(FR)x = F(Rx) rotates first. Reflecting e1e_1 across the xx-axis leaves it alone, and rotating gives (0,1)⊤(0, 1)^\top, so the right product is RFRF (Problem 3). The factor nearest xx acts first: in a network W2W1xW_2W_1x, the layer W1W_1 is applied first.

3. Coordinates found with P instead of P⁻¹

PP is the matrix that comes with the basis, and multiplying by it is the obvious thing to do with a new basis.

  1. P=[1112]P = \begin{bmatrix}1&1\\1&2\end{bmatrix} and v=(3,5)⊤v = (3, 5)^\topRight so far: Problem 5.
  2. “To express vv in the new basis, apply the basis matrix to it.”The shortcut that causes the mistake: PP goes from BB-coordinates to standard ones, not the other way.
  3. [v]B=Pv=(8,13)⊤[v]_B = Pv = (8, 13)^\topThen 8b1+13b2=(21,34)⊤8b_1 + 13b_2 = (21, 34)^\top, not vv. The coordinates solve Pc=vPc = v, so [v]B=P−1v=(1,2)⊤[v]_B = P^{-1}v = (1, 2)^\top (Problem 5). Rebuilding vv from the claimed coordinates catches the error at once.

4. Pᵀ used as P⁻¹ for a basis that is not orthonormal

Orthogonal basis vectors look like the case where the inverse is the transpose.

  1. P=[1−221]P = \begin{bmatrix}1&-2\\2&1\end{bmatrix}, with orthogonal columns, and v=(3,1)⊤v = (3, 1)^\topRight so far: the basis of Problem 6.
  2. “The columns are orthogonal, so P−1=P⊤P^{-1} = P^\top.”The rule that causes the mistake: P⊤P=IP^\top P = I needs columns of length 11 as well, and these have length 5\sqrt5.
  3. [v]B=P⊤v=(5,−5)⊤[v]_B = P^\top v = (5, -5)^\topP⊤P=5IP^\top P = 5I, so P−1=15P⊤P^{-1} = \tfrac15P^\top and [v]B=(1,−1)⊤[v]_B = (1, -1)^\top: indeed b1−b2=(3,1)⊤b_1 - b_2 = (3, 1)^\top. The transpose gives coordinates 55 times too large, and 5b1−5b2=(15,5)⊤5b_1 - 5b_2 = (15, 5)^\top. Normalize the basis first, as in Problem 10, or divide by the squared lengths.

5. An affine map treated as linear

The recipe “column jj is T(ej)T(e_j)” works so reliably that it gets applied before checking that the map is linear.

  1. T1(x,y)=(x+2y, 3x−y+1)T_1(x, y) = (x + 2y,\ 3x - y + 1), so T1(e1)=(1,4)⊤T_1(e_1) = (1, 4)^\top and T1(e2)=(2,0)⊤T_1(e_2) = (2, 0)^\topRight so far: the map of Problem 2, evaluated correctly.
  2. “Put the images in the columns.”The habit that causes the mistake: the recipe assumes linearity, and T1(0)=(0,1)⊤≠0T_1(0) = (0, 1)^\top \neq 0.
  3. T1=[1240]T_1 = \begin{bmatrix}1&2\\4&0\end{bmatrix}, so T1(1,1)=(3,4)T_1(1, 1) = (3, 4)The true value is T1(1,1)=(3,3)T_1(1, 1) = (3, 3). Each column carries the constant bb, so the matrix applied to (1,1)⊤(1, 1)^\top adds it twice, where T1T_1 adds it once. The map is Ax+bAx + b with A=[123−1]A = \begin{bmatrix}1&2\\3&-1\end{bmatrix} and b=(0,1)⊤b = (0, 1)^\top: read AA from T(ej)−T(0)T(e_j) - T(0).

Print this set: linear-transformations-and-change-of-basis.pdf (problems, answers, and worked solutions on separate pages).