Solution (source code)

= Solution

If $u=0$, any nonzero $w$, for instance the first <Cartesian basis> vector $e_1$, gives $H(w)u=0$ and $\alpha=0$. Suppose $u\ne0$. Choose
$$
\alpha=-\operatorname{sgn}_+(u_1)\|u\|_2,\qquad w=u-\alpha e_1,
$$
where $\operatorname{sgn}_+(r)=1$ for $r\geq0$ and $-1$ otherwise. This choice ensures $w\ne0$, including when $u$ is already on the first coordinate axis. Since $\alpha^2=u^Tu$,
$$
w^Tu=u^Tu-\alpha u_1,\qquad w^Tw=u^Tu-2\alpha u_1+\alpha^2=2(w^Tu).
$$
Therefore the <Householder reflection> satisfies
$$
\boxed{H(w)u=u-\frac{2w(w^Tu)}{w^Tw}=u-w=\alpha e_1.}
$$
The <orthogonality> of $H(w)$, used here to check length preservation, gives $|\alpha|=\|H(w)u\|_2=\|u\|_2$. The chosen sign also avoids <catastrophic cancellation> in $w_1=u_1-\alpha$. This is a <Householder reflection sending a vector to a coordinate axis> with no zero-normal exception.