Chapter 7 Exercises — Matrices as Functions

Work these with pencil first; reach for numpy only where a problem says "code" or asks you to verify. Throughout, $\mathbf{e}_1 = (1,0)$ and $\mathbf{e}_2 = (0,1)$ are the standard basis vectors of $\mathbb{R}^2$, and all transformations fix the origin unless stated otherwise. Tiers: ⭐ conceptual · ⭐⭐ computation (by hand) · ⭐⭐⭐ proof (A) / coding (C) · ⭐⭐⭐⭐ application.

The single habit to practice everywhere: to build a matrix, ask where $\mathbf{e}_1$ and $\mathbf{e}_2$ go; to read a matrix, look at its columns.


⭐ Conceptual (warm-ups)

7.1. In one sentence, what does multiplying a vector by a matrix do to the vector, geometrically?

7.2. True or false, with a one-line reason each: (a) Every matrix represents a linear transformation. (b) Translation by a nonzero vector is a linear transformation. (c) The columns of a matrix are the images of the standard basis vectors. (d) A matrix-vector product can land outside the span of the matrix's columns.

7.3. A transformation moves the origin to $(2, 0)$. Can it be linear? Explain in one sentence.

7.4. Without computing entries, explain why $A\mathbf{e}_1$ always equals the first column of $A$ and $A\mathbf{e}_2$ the second.

7.5. Match each $2\times 2$ matrix to its description (identity, scaling, rotation, shear, reflection, projection): $\begin{bmatrix}1&0\\0&1\end{bmatrix}$, $\begin{bmatrix}1&0\\0&0\end{bmatrix}$, $\begin{bmatrix}0&-1\\1&0\end{bmatrix}$, $\begin{bmatrix}1&2\\0&1\end{bmatrix}$, $\begin{bmatrix}1&0\\0&-1\end{bmatrix}$, $\begin{bmatrix}3&0\\0&3\end{bmatrix}$.

7.6. Explain, in your own words, why this book derives the matrix-vector product as a weighted sum of columns rather than presenting the row-times-column rule first.

7.7. The determinant in the visualizer titles is $1$ for a rotation, $-1$ for a reflection, $0$ for a projection. What does each value tell you geometrically about what the transformation did to the unit square?


⭐⭐ Computation (by hand)

7.8. Compute each matrix-vector product as a weighted sum of columns (show the two scaled columns before adding): (a) $\begin{bmatrix}2&0\\0&3\end{bmatrix}\begin{bmatrix}4\\-1\end{bmatrix}$ (b) $\begin{bmatrix}1&1\\0&1\end{bmatrix}\begin{bmatrix}3\\2\end{bmatrix}$ (c) $\begin{bmatrix}0&-1\\1&0\end{bmatrix}\begin{bmatrix}5\\2\end{bmatrix}$.

7.9. Build the matrix of each transformation by asking where $\mathbf{e}_1$ and $\mathbf{e}_2$ go: (a) stretch horizontally by 4, leave vertical unchanged; (b) reflect across the $y$-axis; (c) rotate $180°$ about the origin; (d) project every point onto the $y$-axis; (e) a vertical shear that sends $\mathbf{e}_1$ to $(1, 3)$ and leaves $\mathbf{e}_2$ fixed.

7.10. Using the derived formula $R(\theta) = \begin{bmatrix}\cos\theta&-\sin\theta\\\sin\theta&\cos\theta\end{bmatrix}$, write the matrix for $\theta = 45°$ (leave $\tfrac{\sqrt2}{2}$ in your answer) and for $\theta = 90°$. Verify each by checking where $\mathbf{e}_1$ lands.

7.11. Read each matrix back into a description (name the transformation and give its determinant): (a) $\begin{bmatrix}0&1\\1&0\end{bmatrix}$ (b) $\begin{bmatrix}\tfrac12&0\\0&\tfrac12\end{bmatrix}$ (c) $\begin{bmatrix}0&3\\-3&0\end{bmatrix}$ (d) $\begin{bmatrix}2&0\\0&0\end{bmatrix}$.

7.12. Compute the transpose of each: (a) $\begin{bmatrix}1&2\\3&4\end{bmatrix}$ (b) $\begin{bmatrix}1&0&5\\-2&7&3\end{bmatrix}$ (c) $\begin{bmatrix}4\\-1\\2\end{bmatrix}$ (a column vector — what shape do you get?).

7.13. For the shear $A=\begin{bmatrix}1&2\\0&1\end{bmatrix}$, compute $A^{\mathsf{T}}$ and describe what transformation $A^{\mathsf{T}}$ performs. Is it the same as $A$? Is it the inverse of $A$? (One sentence each.)

7.14. A transformation $T$ is linear and you observe $T(1,0)=(2,1)$ and $T(0,1)=(-1,3)$. Find $T(3,-2)$ using superposition, without first writing down the matrix. Then write the matrix and confirm.

7.15. Combine transformations by tracking the basis vectors (don't use a matrix-multiplication rule — Chapter 8): first scale by $\begin{bmatrix}2&0\\0&1\end{bmatrix}$, then rotate $90°$ with $\begin{bmatrix}0&-1\\1&0\end{bmatrix}$. What is the combined matrix? Then do them in the opposite order and confirm you get a different matrix.


⭐⭐⭐ Proof (A) and Coding (C)

7.16. (Proof) Prove directly from the two rules of linearity that any linear $T:\mathbb{R}^2\to\mathbb{R}^2$ satisfies $T(\mathbf{0}) = \mathbf{0}$. Then prove that $T(-\mathbf{v}) = -T(\mathbf{v})$ for every $\mathbf{v}$.

7.17. (Proof) Show that the map $T(x,y) = (x^2, y)$ is not linear by exhibiting a single counterexample to additivity or homogeneity. State which rule fails.

7.18. (Proof) Let $A$ be a $2\times 2$ matrix with columns $\mathbf{a}_1, \mathbf{a}_2$. Prove that for every $\mathbf{v}\in\mathbb{R}^2$, the product $A\mathbf{v}$ lies in $\operatorname{span}\{\mathbf{a}_1, \mathbf{a}_2\}$. (This is the seed of the column space, Chapter 13.)

7.19. (Proof) Suppose $T:\mathbb{R}^2\to\mathbb{R}^2$ is linear and $T(\mathbf{e}_1)=T(\mathbf{e}_2)=\mathbf{0}$. Prove that $T(\mathbf{v})=\mathbf{0}$ for every $\mathbf{v}$ — i.e. $T$ is the zero transformation. What is its matrix?

7.20. (Coding, C) Implement apply(A, v) from scratch in pure Python as the weighted sum of the columns of A (outer loop over columns), as described in the Build Your Toolkit callout. Then verify it against numpy for 1,000 random integer matrices and vectors: assert apply(A, v) == (np.array(A) @ np.array(v)).tolist() (cast to int or compare with a tolerance). Print "all passed" on success.

7.21. (Coding, C) Implement transpose(A) from scratch and verify transpose(A) == np.array(A).T.tolist() for several non-square matrices (e.g. $2\times 3$, $3\times 1$, $1\times 4$).

7.22. (Coding, C) Using the recurring visualize_2d from toolkit/visualizer.py (do not modify it), produce a single figure with six subplots showing the identity, a scaling $(2, \tfrac12)$, a $30°$ rotation, the shear $\begin{bmatrix}1&1\\0&1\end{bmatrix}$, the reflection $\begin{bmatrix}1&0\\0&-1\end{bmatrix}$, and the projection $\begin{bmatrix}1&0\\0&0\end{bmatrix}$. Pass each subplot's ax to visualize_2d. Confirm the determinant printed in each title matches what you expect.

7.23. (Coding, C) Write a function rotation(theta_degrees) that builds $R(\theta)$ from np.cos/np.sin (remember to convert degrees to radians). Verify that rotation(30) @ rotation(60) equals rotation(90) to numerical tolerance, and explain in a comment why composing a $30°$ and a $60°$ rotation gives a $90°$ rotation. (Foreshadows Chapter 8.)


⭐⭐⭐⭐ Application

7.24. (Graphics) A 2D game sprite has its four corner points at $(0,0), (1,0), (1,1), (0,1)$. You want to (i) shrink it to half size and (ii) rotate it $90°$ counterclockwise about the origin, in that order (shrink first). Build the matrix for each step by asking where the basis vectors go, find the combined matrix by tracking the basis vectors through both steps, and compute the four transformed corner positions. Then redo it assuming the screen $y$-axis points down (so a "counterclockwise" math rotation looks clockwise on screen) and describe in one sentence how the picture differs.

7.25. (Robotics) A robot's gripper reports a contact force $\mathbf{f} = (3, 4)$ N in the sensor frame. The sensor is mounted rotated $+30°$ relative to the robot's body frame. The force in the body frame is $R(30°)\,\mathbf{f}$. Compute it (you may use numpy), and verify that the magnitude $\lVert\mathbf{f}\rVert$ is unchanged by the rotation. Explain in one sentence why a rotation must preserve magnitude.

7.26. (Economics / dynamics) In a two-state labor model, the monthly transition matrix is $A = \begin{bmatrix}0.95 & 0.10\\ 0.05 & 0.90\end{bmatrix}$ acting on the state vector $(e, u)$ of employed and unemployed counts. (a) Interpret each column of $A$ as "where do this month's employed/unemployed go?" and confirm each column sums to 1 — why must it? (b) Starting from $(e, u) = (900, 100)$, compute the state after one month ($A\mathbf{x}$) and after two months ($A(A\mathbf{x})$) using numpy. (c) In one sentence, predict whether the unemployment fraction is rising or falling, and connect the long-run behavior to a forward reference (eigenvalues, Chapter 23).

7.27. (Data science, preview) A simple "whitening" preprocessing step transforms feature vectors by a matrix $W$ before training. Suppose $W = \begin{bmatrix}\tfrac12 & 0\\ 0 & 2\end{bmatrix}$. (a) Using the visualizer, describe what $W$ does to a cloud of points shaped like the unit square. (b) Why might shrinking one feature's spread while expanding another's be useful before fitting a model? (One or two sentences; full treatment in Chapter 32.) (c) Connect this to the linear layers described in how neural networks work: what is the analogous role of a weight matrix there?