# Construct unitary $Q$ such that $span\{q_1,q_2\} = span\{v_1,v_2\}$ where $v_1,v_2 \in \mathbb{R}^n$ are given as input

Assume also that $v_1,v_2$ are linearly independent, and $q_i \in \mathbb{R}^n$ denotes the $i$-th column of $Q$. This is what I've got so far. First obtain unit vectors $w_1,w_2$ which are orthogonal and $span\{w_1,w_2\} = span\{v_1,v_2\}$. Now compute a Householder matrix $H$ that aligns $w_1$ with $e_1$, i.e. $Hw_1 = e_1$ (since $\|w_1\| = 1$). Since $H$ is unitary, this means that

\begin{align} w_1 \cdot w_2 = Hw_1 \cdot Hw_2 = e_1 \cdot Hw_2 \Rightarrow Hw_2 = e_i \end{align} for some $i \in \{2,...,n\}$. If $i = 2,$ set $q_j = H^{T}e_j$ for $j \in \{1,...,n\}$. Else set $q_i = H^{T}e_2$ and $q_j = H^{T}e_j$ otherwise. Again since $H$ is unitary, we then have $\{q_1,...,q_n\}$ an orthonormal basis for $\mathbb{R}^n,$ i.e. $Q$ unitary. Finally, $q_1 = w_1$ and $q_2 = w_2$, so $span\{q_1,q_2\} = span\{v_1,v_2\}$, as desired.

Does this approach work? And if so, is there a way of doing this where I do NOT have to use Gram-Schmidt process at the beginning and rather to use something more numerically stable like Householder reflectors?

Edit: I believe the following answers my questions. Assume $v_1,v_2$ are unit vectors without loss of generality. Construct a Householder matrices $H_1,H_2$ such that $H_1 v_1 = e_1$, $H_2 e_1 = e_1$, $H_2 H_1 v_2 = e_2$. Define $H = H_2 H_1$. Return $Q = [H^{T} e_1, H^{T} e_2, ... ,H^{T}e_n]$.