<s>[INST] Distance between set and point, confused of partial derivatives. Let $H = \{(x,y,z)\ \in \mathbb{R}^{3}: x^2+y^2 - z^2 + 4 = 0$
Compute the shortest distance between H and point $p=(2,4,0)$.
I am a bit confused because I tried a direct approach.
$$ x^2+y^2 + 4 =  z^2$$
Let $D(H,p) = \sqrt{(2-x)^{2}+(4-y)^{2} + x^{2} + y^{2}+4}$
So I tried compute $$\frac{\partial D}{\partial x} = (\sqrt{2} (-1 + x))/\sqrt{12 - 2 x + x^2 - 4 y + y^2}$$
$$\frac{\partial D}{\partial y} = (\sqrt{2} (-2 + y))/\sqrt{12 - 2 x + x^2 - 4 y + y^2}$$
It seems not nice to compare with zero.
Do you have another idea?
 [/INST] You are after the minimum of $(x-2)^2+(y-4)^2+z^2$ (no, I did not use the square root) under the restriction that $x^2+y^2-z^2=-4$. It is natural to use here the method of Lagrange multipliers. So, one has to solve the system$$\left\{\begin{array}{l}2(x-2)=2\lambda x\\2(y-4)=2\lambda y\\2z=-2\lambda z\\x^2+y^2-z^2=-4.\end{array}\right.$$Its only solutions are $(x,y,z,\lambda)=(1,2,\pm3,-1)$. So, the distance from $H$ to $(2,4,0)$ is$$\sqrt{(1-2)^2+(2-4)^2+(\pm3)^2}=\sqrt{14}.$$
</s>