# How do I find the minimum distance from a point to a graph?

Assume that I have a graph $$(C): y=f(x)$$ and a point $$A(x_0, y_0)$$ How do I find the minimum distance from point A to graph (C)?

-
The minimum distance will be the distance of the perpendicular drawn from $y=f(x)$ to $(x_{0},y_{0})$ – user9413 May 7 '11 at 12:10
Not too sure about the tag I now assigned, but the previous tag (graph) probably wasn't the best tag. Anyway, to make Chandru's comments more explicit: construct the equation of the normal through $y=f(x)$, and find the normal that passes through $(x_0,y_0)$. Finally, find the distance from $(x_0,y_0)$ to the intersection of the normal and the original curve. – J. M. May 7 '11 at 12:13
To construct that normal, chances are you're going to be finding a derivative, so I think calculus is a better tag than algebra-precalculus. – Gerry Myerson May 7 '11 at 12:31

You to find $x^*$ such that $$d^2(x)= (y-y_0)^2 + (x-x_0)^2 =[f(x)-y_0]^2 + (x-x_0)^2$$ is minimized (in fact you want to find the minimal value $d_\text{min} = d(x^*)$). To obtain the result, you have to set the derivative of $d$ with respect to $x$ equal to zero, $$\partial_x d^2(x) = 2(x - x_0) + 2 [ f(x)- y_0] f'(x) =0.\qquad \qquad (1)$$ The solution of this equation gives you $x^*$ and from $x^*$ you obtain $d_\text{min}$. If the solution to (1) is not unique then you take the $x$ which yields the smallest $d(x)$.
The minimization can be reduced to a finite interval $[x_0 - u,x_0+u]$ where $u = |f(x_0) - y_0|$. In other words we do not need to consider arguments $x$ outside this interval because they give points farther away than $(x_0,y_0)$ is to $(x_0,f(x_0))$. The latter point of the graph is merely convenient; any point of the graph could serve instead provided $u$ is defined as the distance from $(x_0,y_0)$ to that. Note that the original question does not specify that $y=f(x)$ is differentiable, so in a more general setting, say $f$ continuous, some nonsmooth optimization methods may be needed. – hardmath May 7 '11 at 13:48