<s>[INST] Shortest distance between two lines in 3-dimensional space Can someone explain to me how to solve this question?
Find the shortest distance between the lines 
$L_1 = \left\{t \begin{bmatrix} 1\\ 1\\ 1\end{bmatrix} : t \in \mathbb{R}\right\}$ and $L_2 = \left\{s \begin{bmatrix} 1\\ 2\\ 3\end{bmatrix} + \begin{bmatrix} 1\\ 0\\ 0\end{bmatrix}: s \in \mathbb{R}\right\}$
Thanks
 [/INST] The difference vector is
$$
d = L_2(s) - L_1(t) 
= s (1,2,3) + (1,0,0) - t (1,1,1) 
= (s - t + 1, 2s - t, 3s - t)
$$
Then
$$
q = \lVert d \rVert^2 = d^2 = (s-t+1)^2 + (2s - t)^2 + (3s - t)^2
$$
Then the gradient is
$$
q_s =2(s-t+1)+ 4 (2s-t) + 6(3s-t) = 28s-12t + 2 \\
q_t = -2(s-t+1)-2(2s-t) -2(3s-t) = -12s+6t-2
$$
It vanishes for
$$
\left(
\begin{array}{rr|r}
 28 & -12 & -2 \\
-12 &   6 &  2
\end{array}
\right)
\to
\left(
\begin{array}{rr|r}
 16 &  -6 &  0 \\
-12 &   6 &  2
\end{array}
\right)
\to
\left(
\begin{array}{rr|r}
 16 &  -6 &  0 \\
  4 &   0 &  2
\end{array}
\right)
\to \\
\left(
\begin{array}{rr|r}
 16 &  -6 &  0 \\
  1 &   0 &  1/2
\end{array}
\right)
\to
\left(
\begin{array}{rr|r}
  0 &  -6 &  -8 \\
  1 &   0 &  1/2
\end{array}
\right)
\to
\left(
\begin{array}{rr|r}
  1 & 0 &  1/2 \\
  0 & 1 &  4/3 
\end{array}
\right)
$$
So $s = 1/2$ und $t = 4/3$. This gives 
$q = d^2 = (1/6)^2 + (-1/3)^2 + (1/6)^2 = 1/18 + 1/9 = 3/18 = 1/6$
and $d = 1/\sqrt{6}$.

(Large version)
</s>