<s>[INST] Perpendicular vectors in 3d Suppose a  vector $v$ in $\mathbb{R}^3 $ 
How can I  find two arbitrary unit vectors $u$ and $u^*$, that are perpendicular to each other and $v$ ?
There are infinitely many solutions, but I cannot hand pick them. I need some function $Q(v)$ = $(u, u^*)$ that deterministically finds a solution, for all non-zero vectors in $\mathbb{R}^3$. 
This is probably a quaternion question, but I would prefer notation in terms of linear algebra. 
 [/INST] $$u^\star = a \times u$$
Pick an arbitrary vector $a$ which is not parallel to $u$ and do a cross product. The result is perpendicular to both vectors. You can use a fixed vector such as $a=\hat{x}$, $a=\hat{y}$ or $a=\hat{z}$ by selecting the least parallel (lowest $a\cdot u$ value).
Alternatively pick any point is space with coordinates $(a,b,c)$ and construct a 3×3 rotation matrix where each column is a unit mutually perpendicular vector
$$ \begin{align} 
 E(a,b,c) & = \begin{bmatrix} 
\frac{\sqrt{b^2+c^2}}{\sqrt{a^2+b^2+c^2}} & 0 & \frac{a}{\sqrt{a^2+b^2+c^2}} \\
\frac{-a b}{\sqrt{a^2+b^2+c^2}\sqrt{b^2+c^2}} & \frac{c}{\sqrt{b^2+c^2}} & \frac{b}{\sqrt{a^2+b^2+c^2}} \\
\frac{-a c}{\sqrt{a^2+b^2+c^2}\sqrt{b^2+c^2}} & \frac{-b}{\sqrt{b^2+c^2}} & \frac{c}{\sqrt{a^2+b^2+c^2}}
\end{bmatrix} \end{align} $$
</s>