Closest Point to a vector in a subspace

Given v = [0 -3 -8 3], find the closest point to v in the subspace W spanned by [6 6 6 -1] and [6 5 -1 60]. This is web homework problem and I have used the formula (DotProduct(v, w.1)/DotProduct(w.1, w.1))*w.1 + (DotProduct(v, w.2)/DotProduct(w.2, w.2))*w.2 but the computer said the answer I got was wrong. If this isn't the formula than I'm not sure what is. I have triple checked my calculations as well.

Any help would be greatly appreciated.

The projection of a vector $v$ over $\mathrm{span}(w_1, w_2)$ is the sum of the projections of $v$ over $w_1$ and $w_2$, if $w_1$ and $w_2$ are orthogonal. If they're not, you can find other vector that span the same subspace, using Gram-Schmidt's process. For example: $$\mathrm{proj}_{w_1} v = \frac{\langle v, w_1\rangle}{\langle w_1, w_1\rangle}w_1$$ The easy way to remember this formula is to think: if the projection goes in $w_1$'s direction, then it should be natural that $w_1$ appears the most in the formula. Think that $w_1$ guides $v$ through the right direction. Having this in mind, the exercise is just a calculation.

(also, I strongly suggest you look a bit about MathJax and LaTeX, so you can write formulas and stuff here right, otherwise, your question is not very visually appealing to people around here)

• Thank you! I will look into that. Thank you for editing my other question as well. Jun 12 '14 at 22:12
• And you can always accept and/or upvote any answer that you find useful. I hope you can do your exercise now. If you need any more enlightment, just say here (: Jun 12 '14 at 22:14
• @IvoTerek note that your answer only holds in case the $w_1$ and $w_2$ vectors are orthogonal, not in the general case Jun 13 '14 at 0:51
• Oh, yes! I forgot to put there, thank you very much. Fixed. Jun 13 '14 at 0:56
• So you would need to apply Gramm Schmidt to generate an orthogonal basis from the given basis and then apply the projection? Sep 6 '18 at 7:20

$\def\\#1{{\bf#1}}$Let $\\v=(0,-3,-8,3)$, $\\w_1=(6,6,6,-1)$ and $\\w_2=(6,5,-1,60)$. If we write $$\\v=\lambda_1\\w_1+\lambda_2\\w_2+\\w\ ,\tag{*}$$ where $\\w$ is perpendicular to both $\\w_1$ and $\\w_2$, then $$\\p=\lambda_1\\w_1+\lambda_2\\w_2\tag{*\!*}$$ will be the point in $W$ which is closest to $\\v$. If you don't understand why, draw a picture of the situation - but make it in $\Bbb R^3$ rather than $\Bbb R^4$.

To do the calculations, take the dot product of $(*)$ with both $\\w_1$ and $\\w_2$, remembering that the dot products with $\\w$ will be zero. We get \eqalign{ \\v\cdot\\w_1&=\lambda\\w_1\cdot\\w_1+\lambda\\w_2\cdot\\w_1\cr \\v\cdot\\w_2&=\lambda\\w_1\cdot\\w_2+\lambda\\w_2\cdot\\w_2\ .\cr} Since $\\v,\\w_1$ and $\\w_2$ are known you can calculate all the coefficients, then solve the system to find $\lambda_1$ and $\lambda_2$, then substitute back into $(**)$ to find the answer.

BTW the $60$ in $\\w_2$ looks odd, are you sure it is correct?

• Yes it is correct unfortunately. For web homework they like to give us ridiculous numbers. Thank you for your help though! Jun 13 '14 at 3:26

call the projection of $v$ in such space $p$, so the vector $v-p$ is normal to both $w_1$ and $w_2$, that is to say that the following equations hold $$(v-p).w_1=0$$ $$(v-p).w_2=0$$ so $$v.w_1=p.w_1$$ $$v.w_2=p.w_2$$

since $p$ is in the space spanned by $w_1$ and $w_2$, we now that, for some scalars $a$ and $b$ $$p=a w_1 + b w_2$$ replacing in the former equations $$\left( \begin{array}{cc} v . w_1 \\ v . w_2 \\ \end{array} \right) = \left( \begin{array}{cc} |w_1|^2 & w_1.w_2 \\ w_1.w_2 & |w_2|^2 \\ \end{array} \right) . \left( \begin{array}{cc} a \\ b \\ \end{array} \right)$$ from here you can solve for $a$ and $b$, and then find $p$ from $p=a w_1 + b w_2$. This procedure does not require that the vectors $w_1$ and $w_2$ are orthogonal.