What the System Solves
Given and , a linear least-squares problem asks for the parameter vector that makes the residual as small as possible:
Every minimizer satisfies the normal equation
This equation is always consistent. The minimizer is unique exactly when , which requires . In that full-column-rank case,
When is rank deficient, the fitted vector is still unique, but the parameter vector is not. If is one solution, then every solution is in
Why a Solution Always Exists
The column space of is a finite-dimensional closed subspace of . Therefore, has a unique orthogonal projection onto it. Any satisfying is a least-squares solution.
The normal equation expresses the same geometry because
This equation says that the residual is orthogonal to every column of .
Moore Penrose Pseudoinverse
The Moore-Penrose pseudoinverse is defined for every real matrix, including rectangular and rank-deficient matrices. Write its singular value decomposition as
The displayed factorization is a singular value decomposition. To form the pseudoinverse, replace every nonzero singular value with and leave every zero singular value at zero. This gives
The vector is the unique least-squares solution with minimum Euclidean norm. When has full column rank, the general definition simplifies to
The pseudoinverse is uniquely characterized by the four Penrose identities:
Direct Solution with QR Decomposition
For a full-column-rank matrix with , use the thin decomposition
The least-squares objective separates into
The second term does not depend on . Therefore, the minimizer is obtained by solving the upper-triangular system
This route solves the original least-squares problem directly. It does not form and then solve the normal equation.
Worked Polynomial Fit Example
The numerical factors and coefficients below are rounded to five decimal places. The exact matrix equalities hold before rounding.
Fit to seven observations. The design matrix and observation vector are
Each row of is . One valid thin decomposition is
Signs of matching columns of and rows of may change between valid implementations. The product and final fit do not change.
First compute
Then use back substitution:
The calculation gives:
Choosing a Numerical Method
| Method | Approximate dense cost for | Main strength | Main limitation |
|---|---|---|---|
| Normal equations and Cholesky | form in , then factor in about flops | fast when the problem is well conditioned and full rank | |
| Householder | about flops | avoids forming and is usually more stable | requires a rank-aware variant when columns are dependent |
| more work than | determines rank and gives the minimum-norm solution | highest cost of the three |
Use as the usual choice for dense, full-rank problems. Use when the matrix is rank deficient, severely ill conditioned, or requires a minimum-norm solution. Form the normal matrix only when the speed gain is worth the loss of numerical stability. Do not compute an inverse explicitly in production code.