The least-squares problem
minw∥Xw−y∥2 is, geometrically, an orthogonal projection: when
y∈/C(X) no exact solution exists, and the optimum requires
Xw to equal the orthogonal projection
y^=Py of
y onto the column space
C(X), with residual
r=y−Xw orthogonal to
C(X), i.e.
XT(y−Xw)=0, giving the normal equations
XTXw=XTy; with full column rank,
w=(XTX)−1XTy. The projection matrix
P=X(XTX)−1XT is idempotent (
P2=P) and symmetric (
PT=P), and
I−P projects onto
N(XT). When
X is rank-deficient or
XTX ill-conditioned, use the pseudoinverse
X+=VΣ+UT (from the SVD;
Σ+ inverts nonzero singular values), giving the minimum-norm solution
w=X+y.