Solution (source code)

= Solution

Apply the <least-squares normal equations> to the transformed <matrix> and <vector>:
$$
\boxed{(WA)^T(WA)\widehat x_w=(WA)^TWb},
$$
or equivalently
$$
\boxed{A^TW^TWA\widehat x_w=A^TW^TWb}.
$$
Here $W^TW=\operatorname{diag}(w_1^2,\ldots,w_m^2)$. A unique minimizing <vector> exists when the weighted design <matrix> has full column rank; the equations themselves remain valid without that assumption.