[Math] Finding the max/min distance from an ellipse to a line (Lagrange Multiplier Method)

lagrange multiplieroptimization

An ellipse is specified $ x^2 + 4y^2 = 4$, and a line is specified $x + y = 4$. I need to find the max/min distances from the ellipse to the line.

My idea is to find two points $(x_1, y_1)$ and $(x_2,y_2)$ such that the first point is on the ellipse and the second point is on the line. Furthermore, the line segment formed by these two points should be perpendicular to the line (slope = 1). This gives 3 constraints $g_i$ and an objective $f$.

$$ g_1: x_1 ^2 + 4y_1 ^2 – 4 = 0$$
$$ g_2: x_2 + y_2 – 4= 0 $$
$$ g_3:\frac{(y_2 – y_1)}{(x_2 – x_1)} – 1 = 0 $$
$$ f: (y_2 – y_1)^2 + (x_2- x_1)^2 $$

Then I compute $\nabla g_i$ and $\nabla f$:

$$ \nabla g_1 = (2x_1, 8y_1, 0, 0) $$
$$ \nabla g_2 = (0, 0, 1, 1)$$
$$ \nabla g_3 = ( (y_2 – y_1)(x_2 – x_1)^{-2}, -(x_2 – x_1)^{-1}, -(y_2 – y_1)(x_2 – x_1)^{-2}, (x_2 – x_1)^{-1} )$$
$$ \nabla f = (-2(x_2-x_1), -2(y_2-y_1), 2(x_2-x_1), 2(y_2 – y_1))$$

At this point I try to solve $\nabla f = \sum\lambda_i\nabla g_i$, which, together with the constraints, gives me 7 equations with 7 variables. I'm not sure how to solve this system.

$$\lambda_1 2 x_1 + \lambda_3(y_2-y_1)(x_2-x_1)^{-2} = -2(x_2-x_1)$$
$$\lambda_1 8 y_1 – \lambda_3 (x_2 – x_1)^{-1} = -2 (y_2 – y_1)$$
$$\lambda_2 – \lambda_3 (y_2 – y_1)(x_2 – x_1)^{-2} = 2(x_2 – x1)$$
$$\lambda_2 + \lambda_3 (x_2 – x_1)^{-1} = 2(y_2 -y_1)$$

Is there an easy way to see the solutions of this system in $x_1, y_1, x_2, y_2$? If not, is there an easier formulation of this optimization problem?

Best Answer

The ellipse is

$$x^2+4y^2=4\iff \frac{x^2}{2^2}+y^2=1$$

and the line is $\,y=-x+4\,$ , which is then "above" the ellipse all the time and, in particular, in the first quadrant (draw an approximate sketck of the functions to see why is this relevant).

Thus, we can write down a point on the ellipse in the first quadrant as

$$\left(x\,,\,\frac{1}{2}\sqrt{4-x^2}\right)\;,\;\;x\ge 0$$

so using the formula for the distance between a point as above and the line $\,x+y-4=0\,$ we get

$$\frac{\left|\;x+\frac{1}{2}\sqrt{4-x^2}-4\;\right|}{\sqrt2}=\frac{\left|\;2x+\sqrt{4-x^2}-8\;\right|}{2\sqrt2}$$

But since the expression with the absolute value is always negative (in $\,0\le x\le 2\,$ , that is)(why?) , we must get the minimum of:

$$f(x)=\frac{-2x-\sqrt{4-x^2}+8}{2\sqrt 2}\implies f'(x)=\frac{-2+\frac{x}{\sqrt{4-x^2}}}{2\sqrt 2}=0\iff$$

$$-2\sqrt{4-x^2}+x=0\iff x^2=16-4x^2\iff x=\frac{4}{\sqrt 5}$$

Check the above indeed is a minimum point and input in the resp. equation...

Of course, the maximal distance is...