Chapter 2 Exercises — Vectors
Work the hand problems with pencil first, then check with numpy where indicated. Problems are graded by difficulty: ⭐ conceptual, ⭐⭐ hand computation, ⭐⭐⭐ proof (math-major track) or coding (CS/data track), ⭐⭐⭐⭐ application. A [A] tag marks a proof; a [C] tag marks a coding problem. Selected answers appear in the appendix.
Throughout, $\mathbf{u} = \begin{bmatrix} 3 \\ 1 \end{bmatrix}$, $\mathbf{v} = \begin{bmatrix} 1 \\ 2 \end{bmatrix}$, $\mathbf{w} = \begin{bmatrix} -2 \\ 4 \end{bmatrix}$ unless a problem says otherwise.
⭐ Conceptual
2.1 In one sentence each, give the two equivalent definitions of a vector covered in this chapter (the geometric and the algebraic). What is the bridge that connects them?
2.2 True or false, with a one-line reason: an arrow drawn from $(2,2)$ to $(5,3)$ and an arrow drawn from $(0,0)$ to $(3,1)$ represent the same vector.
2.3 Explain why vector addition is commutative using the parallelogram picture — no algebra. Then state which arithmetic property of real numbers makes it commutative in the componentwise formula.
2.4 What geometric effect does multiplying a vector by each of these scalars have: $4$, $\tfrac13$, $0$, $-1$, $-3$? Match each to "stretch," "shrink," "flip," "flip-and-stretch," or "collapse to origin."
2.5 A classmate writes $|\mathbf{v}|$ for the length of a vector $\mathbf{v}$. What notation should they use instead, and why does the single-bar notation invite confusion later in the book?
2.6 Explain in words why you cannot add a vector in $\mathbb{R}^2$ to a vector in $\mathbb{R}^3$. Is there any picture for such a sum?
2.7 Why does this book stack a vector's components vertically (as a column) by default? Give the forward-looking reason involving matrix–vector multiplication.
2.8 A linear combination of $\mathbf{v}_1$ and $\mathbf{v}_2$ uses weights that sum to 1. Geometrically, where must the result lie? What is the special name for the weight-$(\tfrac12,\tfrac12)$ case?
⭐⭐ Hand Computation
2.9 Compute by hand: (a) $\mathbf{u} + \mathbf{v}$, (b) $\mathbf{v} + \mathbf{u}$, (c) $\mathbf{u} - \mathbf{v}$, (d) $\mathbf{v} - \mathbf{u}$. Comment on how (a)/(b) compare and how (c)/(d) compare.
2.10 Compute: (a) $3\mathbf{u}$, (b) $-2\mathbf{v}$, (c) $\tfrac12\mathbf{w}$, (d) $0\,\mathbf{w}$.
2.11 Compute the linear combination $2\mathbf{u} - \mathbf{v} + \tfrac12\mathbf{w}$ by hand.
2.12 Find the vector represented by the arrow from the point $(-1, 3)$ to the point $(4, -2)$. Then find its magnitude.
2.13 Compute the magnitudes $\lVert \mathbf{u} \rVert$, $\lVert \mathbf{v} \rVert$, and $\lVert \mathbf{w} \rVert$. Which vector is longest? Leave answers in exact (square-root) form.
2.14 Compute the magnitude of $\begin{bmatrix} 2 \\ 3 \\ 6 \end{bmatrix}$ and of $\begin{bmatrix} 1 \\ 4 \\ 8 \end{bmatrix}$. (Both are Pythagorean — your answers should be whole numbers.)
2.15 Find the midpoint of the points $(2, 7)$ and $(8, 1)$, and the point three-quarters of the way from the first to the second.
2.16 Using $\lVert c\mathbf{v}\rVert = |c|\,\lVert \mathbf{v}\rVert$ and $\lVert \mathbf{u}\rVert = \sqrt{10}$, find $\lVert -3\mathbf{u} \rVert$ without recomputing from components.
2.17 Find weights $c_1, c_2$ so that $c_1 \begin{bmatrix} 1 \\ 0 \end{bmatrix} + c_2 \begin{bmatrix} 1 \\ 1 \end{bmatrix} = \begin{bmatrix} 5 \\ 2 \end{bmatrix}$. (Hint: read off the second component first.)
⭐⭐⭐ Proof [A] / Coding [C]
2.18 [A] Prove the distributive law $c(\mathbf{u} + \mathbf{v}) = c\mathbf{u} + c\mathbf{v}$ for vectors in $\mathbb{R}^n$, working componentwise and citing the corresponding property of real numbers at the step where you use it. State clearly what you are allowed to assume.
2.19 [A] Prove that the zero vector is unique: if $\mathbf{z}$ is a vector such that $\mathbf{v} + \mathbf{z} = \mathbf{v}$ for every $\mathbf{v} \in \mathbb{R}^n$, then $\mathbf{z} = \mathbf{0}$. (Hint: a statement true for every $\mathbf{v}$ is in particular true for a convenient one.)
2.20 [A] Prove that $\lVert c\mathbf{v}\rVert = |c|\,\lVert\mathbf{v}\rVert$ for every scalar $c$ and vector $\mathbf{v} \in \mathbb{R}^n$. Identify the exact step where the absolute value (rather than $c$ itself) becomes necessary, and explain why.
2.21 [A] Prove that if $\mathbf{a}$ and $\mathbf{b}$ are nonzero vectors in $\mathbb{R}^2$ with $\mathbf{b}$ not a scalar multiple of $\mathbf{a}$, then for any target $\mathbf{t} \in \mathbb{R}^2$ there exist weights $c_1, c_2$ with $c_1\mathbf{a} + c_2\mathbf{b} = \mathbf{t}$. (Set up the two component equations and argue the system has a solution. You may use that a $2\times 2$ system with the relevant non-proportionality has a unique solution — Chapter 3 makes this rigorous.)
2.22 [C] Implement add(u, v), scale(c, v), and magnitude(v) as pure-Python functions on lists (no numpy). Then write a short test that checks each against numpy (np.array(...) + ..., c * np.array(...), np.linalg.norm(...)) on at least three vectors of different dimensions, using np.allclose / math.isclose for the magnitude check. This is the chapter's Build Your Toolkit task — save it as toolkit/vectors.py.
2.23 [C] Write a function lerp(a, b, t) (pure Python, lists) that returns $(1-t)\mathbf{a} + t\mathbf{b}$. Verify that lerp(a, b, 0) returns a, lerp(a, b, 1) returns b, and lerp(a, b, 0.5) returns the midpoint, for a = [1, 2], b = [5, 4]. Check against numpy.
2.24 [C] Using numpy, generate 5 random vectors in $\mathbb{R}^3$ (np.random.randn(5, 3)), compute their centroid with .mean(axis=0), and verify it equals the sum of the five vectors divided by 5. Print both and confirm with np.allclose.
⭐⭐⭐⭐ Application
2.25 (Navigation.) A kayaker paddles with velocity $\begin{bmatrix} 4 \\ 0 \end{bmatrix}$ km/h (due east) across a river whose current flows $\begin{bmatrix} 0 \\ 3 \end{bmatrix}$ km/h (due north). (a) Find the kayaker's velocity relative to the ground. (b) Find the ground speed (magnitude). (c) The river is 1 km wide (east–west). How long until the kayaker reaches the far bank, and how far downstream (north) will they have drifted? Verify part (a)–(b) with numpy.
2.26 (Graphics / color.) In RGB, a color is a vector of three components (red, green, blue), each $0$–$255$. Pure red is $\begin{bmatrix} 255 \\ 0 \\ 0 \end{bmatrix}$ and pure blue is $\begin{bmatrix} 0 \\ 0 \\ 255 \end{bmatrix}$. (a) Compute the color exactly halfway between them (the lerp at $t = 0.5$). (b) Compute the color one-quarter of the way from red to blue. (c) In one sentence, explain why animating $t$ from 0 to 1 produces a smooth fade. Check (a)/(b) with numpy.
2.27 (Data science.) Three customers are described by feature vectors $[\text{age}, \text{visits/month}, \text{avg spend}]$: $\mathbf{c}_1 = \begin{bmatrix} 25 \\ 8 \\ 40 \end{bmatrix}$, $\mathbf{c}_2 = \begin{bmatrix} 41 \\ 2 \\ 120 \end{bmatrix}$, $\mathbf{c}_3 = \begin{bmatrix} 33 \\ 5 \\ 80 \end{bmatrix}$. (a) Compute the average customer (centroid). (b) Which single customer is "closest" to the centroid, measuring closeness by the magnitude of the difference vector? Do this with numpy and report the three distances.