Tutorials › Calculus III › Deriving Projection by Minimizing Distance

Dot Products and Projections · Tutorial 61 of 999

Deriving Projection by Minimizing Distance

Learn to find the closest scalar multiple of a direction vector by minimizing a quadratic distance function, and derive the vector projection formula.

Beginner 9 min read

What You'll Learn

  • Set up squared distance from a vector to a scalar multiple of a nonzero direction vector.
  • Complete the square to locate and justify the unique minimum.
  • Derive the vector projection formula from the minimizing scalar.
  • Verify projections by checking the minimum distance directly.
  • Recognize why the direction vector must be nonzero and why rescaling it does not change the projection.
  • Identify and correct a common denominator error in the projection formula.

Introduction

A projection onto a line answers a nearest-point question: among all vectors pointing along a chosen direction, which one is closest to a given vector? The answer can be derived by measuring the distance to a general candidate on the line and choosing the candidate that makes that distance as small as possible.

This approach connects the projection formula to a basic optimization problem. The unknown is a single real number: the scalar that multiplies the direction vector. Once the distance is written in terms of that scalar, the problem becomes minimizing a quadratic function.

Set Up the Distance Problem

Let \(\mathbf{a}\) be the vector we want to approximate, and let \(\mathbf{v}\) be a nonzero direction vector. The line through the origin with direction \(\mathbf{v}\) consists of all vectors \(t\mathbf{v}\), where \(t\) is a real number. The distance from \(\mathbf{a}\) to a particular candidate \(t\mathbf{v}\) is \(\|\mathbf{a}-t\mathbf{v}\|\).

It is more convenient to minimize the squared distance. Since distance is nonnegative and squaring preserves the order of nonnegative numbers, minimizing the distance and minimizing its square give the same candidate.

Definition: For a fixed vector \(\mathbf{a}\) and nonzero direction vector \(\mathbf{v}\), define the squared-distance function \(D(t)=\|\mathbf{a}-t\mathbf{v}\|^2\), for \(t\in\mathbb{R}\). A minimizing scalar is a real number \(t_*\) for which \(D(t_*)\leq D(t)\) for every real \(t\).

The condition \(\mathbf{v}\ne\mathbf{0}\) matters. It ensures that \(\mathbf{v}\cdot\mathbf{v}>0\), so the line has a genuine direction and the quadratic distance function has a positive coefficient on \(t^2\).

Deriving the Minimizing Scalar

Use the dot product identity \(\|\mathbf{x}\|^2=\mathbf{x}\cdot\mathbf{x}\), together with linearity and symmetry of the dot product, to expand \(D(t)\):

$$ \begin{aligned} D(t) &=(\mathbf{a}-t\mathbf{v})\cdot(\mathbf{a}-t\mathbf{v})\\ &=\mathbf{a}\cdot\mathbf{a} -t(\mathbf{a}\cdot\mathbf{v}) -t(\mathbf{v}\cdot\mathbf{a}) +t^2(\mathbf{v}\cdot\mathbf{v})\\ &=\mathbf{a}\cdot\mathbf{a} -2t(\mathbf{a}\cdot\mathbf{v}) +t^2(\mathbf{v}\cdot\mathbf{v}). \end{aligned} $$

Because \(\mathbf{v}\ne\mathbf{0}\), the number \(\mathbf{v}\cdot\mathbf{v}\) is positive. We can therefore complete the square, keeping track of the part that does not depend on \(t\):

$$ D(t) = (\mathbf{v}\cdot\mathbf{v}) \left(t-\frac{\mathbf{a}\cdot\mathbf{v}}{\mathbf{v}\cdot\mathbf{v}}\right)^2 + \mathbf{a}\cdot\mathbf{a} -\frac{(\mathbf{a}\cdot\mathbf{v})^2}{\mathbf{v}\cdot\mathbf{v}}. $$

The squared term is always nonnegative, and its coefficient is positive. It is zero at exactly one value of \(t\). Thus this value gives the unique global minimum, not merely a candidate for a minimum.

Result: The squared distance from \(\mathbf{a}\) to \(t\mathbf{v}\) is minimized uniquely when \(t_*=\dfrac{\mathbf{a}\cdot\mathbf{v}}{\mathbf{v}\cdot\mathbf{v}}\). The closest vector on the line is therefore \(\operatorname{proj}_{\mathbf{v}}\mathbf{a}=\dfrac{\mathbf{a}\cdot\mathbf{v}}{\mathbf{v}\cdot\mathbf{v}}\mathbf{v}\), where \(\mathbf{v}\ne\mathbf{0}\).

The scalar \(t_*\) specifies how much of \(\mathbf{v}\) to take. The vector projection is the scalar multiplied by \(\mathbf{v}\). These are different kinds of quantities: \(t_*\) is a number, while \(\operatorname{proj}_{\mathbf{v}}\mathbf{a}\) is a vector.

Worked Examples

Worked Example: Find a Projection by Minimizing Distance

Find the vector on the line of multiples of \(\mathbf{v}=(1,2,2)\) closest to \(\mathbf{a}=(3,4,0)\).

First calculate the dot products:

$$ \mathbf{a}\cdot\mathbf{v} =(3)(1)+(4)(2)+(0)(2) =3+8+0 =11, $$
$$ \mathbf{v}\cdot\mathbf{v} =(1)(1)+(2)(2)+(2)(2) =1+4+4 =9. $$

Hence the minimizing scalar is \(t_*=11/9\). The closest vector is

$$ t_*\mathbf{v} =\frac{11}{9}(1,2,2) =\left(\frac{11}{9},\frac{22}{9},\frac{22}{9}\right). $$

To check the minimization, the squared-distance function is

$$ D(t)=\|\mathbf{a}\|^2-2t(11)+9t^2 =25-22t+9t^2 =9\left(t-\frac{11}{9}\right)^2+\frac{104}{9}. $$

The square term is minimized at \(t=11/9\). Directly, the residual is

$$ \mathbf{a}-t_*\mathbf{v} =\left(3-\frac{11}{9},\,4-\frac{22}{9},\,0-\frac{22}{9}\right) =\left(\frac{16}{9},\frac{14}{9},-\frac{22}{9}\right). $$

Its squared length is \((256+196+484)/81=936/81=104/9\), exactly the minimum shown by completing the square. The projection is verified.

Worked Example: A Negative Minimizing Scalar

Find the closest vector on the line of multiples of \(\mathbf{v}=(2,-1,2)\) to \(\mathbf{a}=(-2,5,1)\).

Compute the dot products, showing each contribution:

$$ \mathbf{a}\cdot\mathbf{v} =(-2)(2)+(5)(-1)+(1)(2) =-4-5+2 =-7, $$
$$ \mathbf{v}\cdot\mathbf{v} =(2)(2)+(-1)(-1)+(2)(2) =4+1+4 =9. $$

The minimizing scalar is \(t_*=-7/9\). Therefore, the closest vector is

$$ t_*\mathbf{v} =-\frac{7}{9}(2,-1,2) =\left(-\frac{14}{9},\frac{7}{9},-\frac{14}{9}\right). $$

Here \(\|\mathbf{a}\|^2=4+25+1=30\), so the full distance function is

$$ D(t)=30-2t(-7)+9t^2 =30+14t+9t^2 =9\left(t+\frac{7}{9}\right)^2+\frac{221}{9}. $$

This confirms that \(t=-7/9\) uniquely minimizes \(D(t)\). For a direct check, subtract the projected vector from \(\mathbf{a}\):

$$ \mathbf{a}-t_*\mathbf{v} =\left(-2+\frac{14}{9},\,5-\frac{7}{9},\,1+\frac{14}{9}\right) =\left(-\frac{4}{9},\frac{38}{9},\frac{23}{9}\right). $$

The squared length of this residual is \((16+1444+529)/81=1989/81=221/9\), agreeing with the minimum in \(D(t)\). The negative scalar is appropriate: the closest multiple points in the direction opposite to the displayed \(\mathbf{v}\).

Worked Example: Rescaling the Direction Vector

Let \(\mathbf{a}=(4,1,-2)\) and \(\mathbf{v}=(-1,2,2)\). Find the projection, then check that using \(-2\mathbf{v}\) gives the same vector.

For \(\mathbf{v}\), the dot products are

$$ \mathbf{a}\cdot\mathbf{v} =(4)(-1)+(1)(2)+(-2)(2) =-4+2-4=-6, $$
$$ \mathbf{v}\cdot\mathbf{v} =(-1)^2+2^2+2^2=1+4+4=9. $$

Thus \(t_*=-6/9=-2/3\), giving

$$ t_*\mathbf{v} =-\frac{2}{3}(-1,2,2) =\left(\frac{2}{3},-\frac{4}{3},-\frac{4}{3}\right). $$

Now set \(\mathbf{w}=-2\mathbf{v}=(2,-4,-4)\). Then

$$ \mathbf{a}\cdot\mathbf{w} =(4)(2)+(1)(-4)+(-2)(-4) =8-4+8=12, $$
$$ \mathbf{w}\cdot\mathbf{w} =2^2+(-4)^2+(-4)^2 =4+16+16=36. $$

The minimizing scalar for \(\mathbf{w}\) is \(12/36=1/3\), so the resulting vector is

$$ \frac{1}{3}\mathbf{w} =\frac{1}{3}(2,-4,-4) =\left(\frac{2}{3},-\frac{4}{3},-\frac{4}{3}\right). $$

For a distance check, \(\|\mathbf{a}\|^2=16+1+4=21\). Using \(\mathbf{w}\), the squared-distance function is \(21-24t+36t^2=36(t-1/3)^2+17\). The residual at the minimum is \((10/3,7/3,-2/3)\), whose squared length is \((100+49+4)/9=153/9=17\). Thus the minimum is verified, and both direction vectors give the same projection.

Why Rescaling Does Not Change the Projection

The last example illustrates a general fact. Replacing a nonzero direction vector \(\mathbf{v}\) by \(c\mathbf{v}\), with \(c\ne0\), changes its scale but not the line of its multiples. The formula confirms that the projected vector is unchanged:

$$ \frac{\mathbf{a}\cdot(c\mathbf{v})}{(c\mathbf{v})\cdot(c\mathbf{v})}(c\mathbf{v}) = \frac{c(\mathbf{a}\cdot\mathbf{v})}{c^2(\mathbf{v}\cdot\mathbf{v})}(c\mathbf{v}) = \frac{\mathbf{a}\cdot\mathbf{v}}{\mathbf{v}\cdot\mathbf{v}}\mathbf{v}. $$

The scalar that describes the multiple does change when the direction vector is rescaled; the closest vector itself does not. This distinction is useful when a direction is given in a convenient but non-unit form.

A Common Denominator Error

A frequent mistake is to divide by \(\|\mathbf{v}\|\) rather than by \(\mathbf{v}\cdot\mathbf{v}=\|\mathbf{v}\|^2\). For the first example, \(\mathbf{a}\cdot\mathbf{v}=11\) and \(\|\mathbf{v}\|=3\). Using \(11/3\) as the coefficient would give the incorrect candidate \((11/3,22/3,22/3)\).

The error can be detected by checking the distance function from that example. Its derivative is \(D'(t)=18t-22\); at the incorrect value \(t=11/3\), this is \(18(11/3)-22=66-22=44\), not zero. More directly, the completed-square form \(D(t)=9(t-11/9)^2+104/9\) shows that \(11/3\) is not the minimizing scalar.

The correction is to use the squared length in the denominator: \(\mathbf{v}\cdot\mathbf{v}=9\), so the coefficient is \(11/9\). The denominator is not an arbitrary adjustment. It is the positive quadratic coefficient that appears when the squared distance is expanded and completed to a square.

When the Derivation Applies

This minimization considers every real multiple \(t\mathbf{v}\), so it applies to a line through the origin with nonzero direction vector \(\mathbf{v}\). The formula requires \(\mathbf{v}\ne\mathbf{0}\); if \(\mathbf{v}=\mathbf{0}\), its denominator is zero and there is no direction line of this form.

The key method is to express the squared distance as a function of the scalar, expand using dot products, and complete the square. The resulting minimum is unique because the coefficient \(\mathbf{v}\cdot\mathbf{v}\) is strictly positive. This gives both the projection formula and a direct way to verify a proposed answer: its scalar must make the square term vanish.

Check Your Understanding

Use the minimization method in each question. Give exact values where possible.

  1. For \(\mathbf{a}=(1,3,2)\) and \(\mathbf{v}=(1,1,0)\), calculate the minimizing scalar and the vector projection.
  2. Why does minimizing the squared distance give the same candidate as minimizing the distance?
  3. What condition on \(\mathbf{v}\) ensures that the squared-distance quadratic has a positive coefficient on \(t^2\)?
  4. For nonzero \(c\), explain why replacing \(\mathbf{v}\) by \(c\mathbf{v}\) leaves the projected vector unchanged.
  5. What goes wrong if the coefficient in the projection formula is divided by \(\|\mathbf{v}\|\) instead of \(\mathbf{v}\cdot\mathbf{v}\)?