Solution (source code)

= Solution

Let $r=\|u\|_2>0$, and choose $s=1$ if $u_1\geq0$ and $s=-1$ otherwise. Set
$$
w=u+sr e_1.
$$
This vector is nonzero, because $w_1$ has magnitude $|u_1|+r$. Direct computation gives
$$
w^Tu=r(r+su_1),\qquad w^Tw=2r(r+su_1),
$$
so the <Householder transformation> satisfies
$$
\boxed{H(w)u=u-2w\frac{w^Tu}{w^Tw}=u-w=-s\|u\|_2 e_1.}
$$
The first entry is nonzero and every other entry is zero. The sign choice also avoids cancellation when forming the first entry of $w$, which is useful in numerical computation.