Find a point on the line: $y=2x-5$ that is the closest to $P(1,2)$ This is our line: $f(x)=2x-5$
I have to find a point on this line that is the closest to the point $P(1,2)$. How do I go on about solving this? Should I use derivative and distance from the point to the line? I've done this so far:
$d\to$ distance between $P(1,2)$ and $f(x)$
$d= \sqrt{(x_2-x_1)^2+(y_2-y_1)^2}$
But how do I get the $x_2,y_2 $ from $f(x)$?
 A: Actually, there is a simpler way. Since $f$ is a line, the point $P$ and the point on $f$ closest to $P$ will define a line perpendicular to $f$. That means that you can get the equation for the line with slope $m=-\frac{1}{2}$ (the inverse of the reciprocal of the slope of $f$) through the point $(1,2)$, and then find the intersection of that line and $f$.
A: $$minimize \hspace{1.5mm}(x-1)^2+(y-2)^2$$
$$s.t. \hspace{1.5mm} 2x -y -5 = 0$$
Lagrangian function: $$ \mathcal{L} = (x-1)^2+(y-2)^2 + \lambda (2x -y -5) .$$
Thus,
$$\frac{\partial \mathcal{L}}{\partial x} = 2x -2 +2\lambda =0 \Rightarrow \lambda = 1-x.$$
$$\frac{\partial \mathcal{L}}{\partial y} = 2y-4-\lambda =0 \Rightarrow \lambda = 2y -4.$$
Then, $x = 5-2y$. Substituting in the constraint:
$2(5-2y)-y-5 =0 \Rightarrow y = 1.$ As $x = 5-2y$, then $x = 3$. Thus, $(3,1)$ is the only critical point. It is a minimal point because the Hessian
\begin{equation}
H =  \left [ \begin{array}{cc}
2 & 0 \\
0 & 2\\
\end{array} \right]
\end{equation} is positive definite.
A: Analytic solution. Points on the line have coordinates $(x,2x-5)$; minimizing the distance is the same as minimizing the square of the distance, so we can consider
$$
g(x)=(x-1)^2+((2x-5)-2)^2=5x^2-30x+50=5(x^2-6x+10)=5((x-3)^2+1)
$$
The minimum is for $x=3$, which gives the point $(3,1)$.
If you don't see the square in the expression, you can use the derivative:
$$
g'(x)=5(2x-6)
$$
which vanishes for $x=3$.
