# Using Lagrange multipliers to find the shortest distance between two straight lines

A problem asks me to use the method of Lagrange multipliers to find the shortest distance between the straight lines $x=y = z$ and $x = -y, z=2$

(It also warns me that using this method is a bit overkill for this task, so no worries)

I'm actually having trouble to even formulate the problem as the function to minimize, which I assume would be the distance between these two lines, and the constraint, which I'm not entirely sure what would be. Any help is appreciated.

My current thought is that if the two lines are expressed as:

$$\vec{u} = t\pmatrix{1\\1\\1}$$

$$\vec{v} = s\pmatrix{1\\-1\\0} + \pmatrix{0\\0\\2}$$

Then $f(\vec{s},\vec{u})$ should minimize

$$f(\vec{u},\vec{v}) = (t_1 - s_1)^2 + (t_2 + s_2)^2 + (t_3-2)^2$$

Given a certain constraint $g$

Let $\mathrm{x} := (x_1, x_2, x_3)$ and $\mathrm{y} := (y_1, y_2, y_3)$ be two free points in $\mathbb{R}^3$. The Euclidean distance between them is $\|\mathrm{x} - \mathrm{y}\|_2$. If we impose the constraint that each of these two points lie on each of the given lines, then we have the linear equality constraints

$$\begin{bmatrix} 1 & -1 & 0\\ 1 & 0 & -1\end{bmatrix} \mathrm{x} = \begin{bmatrix} 0\\ 0\end{bmatrix}$$

$$\begin{bmatrix} 1 & 1 & 0\\ 0 & 0 & 1\end{bmatrix} \mathrm{y} = \begin{bmatrix} 0\\ 2\end{bmatrix}$$

We want to minimize $\|\mathrm{x} - \mathrm{y}\|_2^2$ subject to these linear equality constraints. Thus, we have an equality-constrained quadratic program. The Lagrangian is the following

$$\mathcal{L} (\mathrm{x}, \mathrm{y}, \lambda, \mu) = \frac{1}{2} \|\mathrm{x} - \mathrm{y}\|_2^2 + \lambda \left(\begin{bmatrix} 1 & -1 & 0\\ 1 & 0 & -1\end{bmatrix} \mathrm{x}\right) + \mu \left(\begin{bmatrix} 1 & 1 & 0\\ 0 & 0 & 1\end{bmatrix} \mathrm{y} - \begin{bmatrix} 0\\ 2\end{bmatrix}\right)$$

The $t_1,t_2,t_3$ should all be $t$, also the $s_1,s_2$ be $s$.

However, it would work if you set $f(t,x,y)=(t-x)^2+(t-y)^2+(t-2)^2$ and $g=x+y=0$ as a constraint.

• This is a good way to solve the problem, but it doesn't seem to involve Lagrange multipliers. – user84413 Mar 1 '15 at 21:52
• @user84413: You are right. Probably use $x=-y$ as a constraint. And set $f$ to be the shortest distance from $(t,t,t)$ to $(x,y,2)$. – KittyL Mar 1 '15 at 21:59
• Thanks, but as @user84413 mentioned, it should be solved using Lagrange multipliers. – Jimmy C Mar 1 '15 at 21:59
• @JimmyC: I edited the answer to include Lagrange multiplier. – KittyL Mar 1 '15 at 22:08