Linear Algebra
6.28 min read

Length and Distance

The length (or norm) of a vector v\mathbf{v} is the square root of its dot product with itself: v=vv=v12++vm2\|\mathbf{v}\| = \sqrt{\mathbf{v} \cdot \mathbf{v}} = \sqrt{v_1^2 + \cdots + v_m^2}. This matches the familiar Pythagorean formula for distance from the origin.

Scaling a vector scales its length proportionally: cv=cv\|c\mathbf{v}\| = |c| \cdot \|\mathbf{v}\|. A vector with length 1 is called a unit vector. Given any nonzero vector v\mathbf{v}, dividing by its length gives a unit vector in the same direction: v^=v/v\hat{\mathbf{v}} = \mathbf{v} / \|\mathbf{v}\|. This is called normalization.

The distance between two vectors u\mathbf{u} and v\mathbf{v} is the length of their difference: Dist(u,v)=uv\text{Dist}(\mathbf{u}, \mathbf{v}) = \|\mathbf{u} - \mathbf{v}\|. Think of u\mathbf{u} and v\mathbf{v} as points, and the vector uv\mathbf{u} - \mathbf{v} as the arrow from v\mathbf{v} to u\mathbf{u}.

Formal View

Definition 6.3 — Length (Norm)
For vRm\mathbf{v} \in \mathbb{R}^m, its length is v:=vv=ivi2\|\mathbf{v}\| := \sqrt{\mathbf{v} \cdot \mathbf{v}} = \sqrt{\sum_i v_i^2}. The squared length is v2=vtv\|\mathbf{v}\|^2 = \mathbf{v}^t \mathbf{v}. If v=1\|\mathbf{v}\| = 1, we call v\mathbf{v} a unit vector, sometimes written v^\hat{\mathbf{v}}.
Definition 6.4 — Distance
The distance between u,vRm\mathbf{u}, \mathbf{v} \in \mathbb{R}^m is
Dist(u,v):=uv=i(uivi)2.\text{Dist}(\mathbf{u}, \mathbf{v}) := \|\mathbf{u} - \mathbf{v}\| = \sqrt{\sum_i (u_i - v_i)^2}.

Why This Matters

Norms and distances give geometry its measurement capabilities — they let us say what "close" and "far" mean.

  • K-nearest neighbors classifiers assign a class to a test point based on the Euclidean distances to training examples
  • Image compression measures reconstruction error by the squared distance xoriginalxcompressed2\|\mathbf{x}_{\text{original}} - \mathbf{x}_{\text{compressed}}\|^2
  • GPS and sensor fusion use norm minimization to find the most likely position given noisy measurements
  • The Frobenius norm of a matrix — the length of all entries as one long vector — measures how far a matrix is from zero

Quiz

Question 1

What is v\|\mathbf{v}\| for v=(3,4)\mathbf{v} = (3, -4)?

Question 2

If v=4\|\mathbf{v}\| = 4, what is 3v\|3\mathbf{v}\|?

Common Mistakes

  • Computing u+v\|\mathbf{u} + \mathbf{v}\| as u+v\|\mathbf{u}\| + \|\mathbf{v}\| — the triangle inequality says u+vu+v\|\mathbf{u} + \mathbf{v}\| \leq \|\mathbf{u}\| + \|\mathbf{v}\|, with equality only when they point in the same direction.
  • Forgetting to take the square root — vv\mathbf{v} \cdot \mathbf{v} is the squared length, not the length.
  • Normalizing the zero vector — division by 0=0\|\mathbf{0}\| = 0 is undefined.