Solution (source code)

= Solution

The <orthonormal> columns give $A^TA=I_n$. Thus $P=AA^T$ is the <orthogonal projection> onto the <column space> of $A$, and
$$
Ax-b=A(x-A^Tb)-(I_m-P)b.
$$
The two terms are <orthogonal>, so the <Pythagorean identity> gives
$$
\|Ax-b\|_2^2=\|x-A^Tb\|_2^2+\|(I_m-AA^T)b\|_2^2.
$$
Only the first term depends on $x$. Consequently the <linear least-squares problem> has the unique answer
$$
\boxed{x_*=A^Tb},\qquad \min_x\|Ax-b\|_2=\|(I_m-AA^T)b\|_2.
$$