# closest point to on $y=1/x$ to a given point

I feel like I'm missing something basic - given a point $(a,b)$ how do I find the closest point to it on the curve $y=1/x$? I tried the direct approach of pluggin in $y=1/x$ into the distance formula but it leads to an order-4 polynomial...

-
Since you will (perhaps) be taking the derivative, you will be dealing with an order $3$-polynomial, and I suspect the solution will be ugly. –  Anon Jan 31 '13 at 0:33
@Anon - the order is 4, after derivation, if I am not mistaken... –  olamundo Jan 31 '13 at 0:34
Yes, you are right, my bad. –  Anon Jan 31 '13 at 0:41
Well, finding the appropriate zero of the polynomial gives you the correct result. If the result itself is ugly, nothing can be done about it. (And I see no reason why the result wouldn't be ugly in the general case.) –  Dejan Govc Jan 31 '13 at 0:57
It has a closed form solution, using the old Cardano-Ferrari solution of the quartic. Not attractive. –  André Nicolas Jan 31 '13 at 1:13

I tried the direct approach of pluggin in y=1/x into the distance formula but it leads to an order-4 polynomial...

That is not a mistake. The ellipse has two maxima and two minima of the distance to $P$ for most locations of point $P$. This leads to a degree $4$ polynomial when solving for the coordinates of the extrema. There is no special geometric relationship between the distance extrema that might make the polynomial easier to solve than the general quartic equation.

-

Well. We have by the distance formula that the point on $xy = 1$ closest to $(a,b)$ will be the solution to: $$\frac{d}{dx}\sqrt{(a-x)^2+(b-\frac{1}{x})^2} = 0$$ Which has the same soutions as $$\frac{d}{dx}\left( (a-x)^2+(b-\frac{1}{x})^2\right)= 0\\ -2(a-x)+\frac{2(b-\frac{1}{x})}{x^2} = 0\\ x^4-ax^3+bx-1=0$$ Which has as the first real solution: $$x==\frac{a}{4}-\frac{1}{2} \surd \left(\frac{a^2}{4}+\frac{2^{1/3} (-4+a b)}{\left(-27 a^2+27 b^2+\sqrt{-4 (-12+3 a b)^3+\left(-27 a^2+27 b^2\right)^2}\right)^{1/3}}+\frac{\left(-27 a^2+27 b^2+\sqrt{-4 (-12+3 a b)^3+\left(-27 a^2+27 b^2\right)^2}\right)^{1/3}}{3\ 2^{1/3}}\right)-\frac{1}{2} \surd \left(\frac{a^2}{2}-\frac{2^{1/3} (-4+a b)}{\left(-27 a^2+27 b^2+\sqrt{-4 (-12+3 a b)^3+\left(-27 a^2+27 b^2\right)^2}\right)^{1/3}}-\frac{\left(-27 a^2+27 b^2+\sqrt{-4 (-12+3 a b)^3+\left(-27 a^2+27 b^2\right)^2}\right)^{1/3}}{3\ 2^{1/3}}-\frac{a^3-8 b}{4 \sqrt{\frac{a^2}{4}+\frac{2^{1/3} (-4+a b)}{\left(-27 a^2+27 b^2+\sqrt{-4 (-12+3 a b)^3+\left(-27 a^2+27 b^2\right)^2}\right)^{1/3}}+\frac{\left(-27 a^2+27 b^2+\sqrt{-4 (-12+3 a b)^3+\left(-27 a^2+27 b^2\right)^2}\right)^{1/3}}{3\ 2^{1/3}}}}\right)$$

And the others are just as complicated. This was produced with Mathematica and simplifying under the assumption that the root was real ,$b>-a$ and, $x>0$.

This is such a simply posed problem, but it seems as if the solution is incredibly complicated.

-

I tried using the property that the tangent of the curve would be perpindicular to the line connecting with the point but it leads to the same polynomial as in the answer of @DoctorBatmanGod (of course).

You didn't state what type of answer you are looking for, so as a practical matter using a root-finding method on the polynomial may be the easiest route, if you need the location of the point for an applied problem. It is pretty apparent how to get a very close starting position.

-

The slope of $y = 1/x$ at $x$ is $-1/x^2$, so the tangent at $(p, 1/p)$ is $(y-1/p)/(x-p) = -1/p^2$ or $y = 1/p - (x-p)/p^2$. At $y = 0$, $(x-p)/p^2 = 1/p$ or $x = 2p$; at $x = 0$, $y = 1/p + p/p^2 = 2/p$. The intercept points are thus $(0, 2/p)$ and $(2p, 0)$.

I will minimize the distance by making the line from $(a, b)$ to $(p, 1/p)$ perpendicular to this tangent at $(p, 1/p)$ and do this by making their dot product zero.

The dot product of the vector from $(a, b)$ to $(p, 1/p)$ with the tangent is

\begin{align} (p-a, 1/p-b)\cdot (2p, -2/p) &= 2p(p-a) - 2/p^2+2b/p \\ &= (2p^3(p-a) - 2 + 2pb)/p^2 \\ &= (2p^4 - 2ap^3 + 2bp-2)/p^2 \\ &= 2(p^4 - ap^3 + bp-1)/p^2 \end{align}

and this is zero when $f(p; a, b) = p^4 - ap^3 + bp-1 = 0$.

I will consider the special case $a = b$ to check this; there should be a root at $p = 1$.

If $a = b$,

\begin{align} f(p; a, a) &= p^4 - ap^3 + ap-1 \\ &= (p^4-1) - a(p^3-1) \\ &= (p-1)(p^3+p^2+p^1 - a(p^2+p+1)) \\ &= (p-1)(p^3 + (1-a)(p^2+p+1)) \end{align}

which has a root at $p = 1$ (as expected) and, if $a > 1$ (so $(a, a)$ is to the right and above the hyperbola), another positive real root since $p^3 + (1-a)(p^2+p+1) < 0$ for small $p$ and $p^3 + (1-a)(p^2+p+1) > 0$ for large $p$.

If $a < 1$, so $(a, a)$ is between the hyperbola and the origin, there are no other positive real roots since $p^3 + (1-a)(p^2+p+1) > 0$ for all $p \ge 0$.

I could argue further about where the real roots of $f(p; a, b)$ are using $f(1/p; a, b) = (1/p)^4 - a(1/p)^3 + b/p-1 = (1 - ap + bp^3 - p^4)/p^4 = -f(p; b, a)/p^4$ so the roots of $f(1/p, a, b)$ are the same as the roots of $f(p; b, a)$, but that's enough for now for me.

In general, I find it much easier algebraically to make two vectors orthogonal by making their dot product zero than minimizing their distance using the Pythagorean theorem.

-
I was using the same approach and posted at about the same time; however I think you should have realized that you arrived at the same polynomial and that solving the polynomial is the part giving difficulty. –  half-integer fan Jan 31 '13 at 2:10