Least Squares and the Pseudoinverse
Least squares finds the vector minimizing when has no exact solution. The unique minimum-norm solution is , where is the Moore–Penrose pseudoinverse. Applies to overdetermined/underdetermined linear systems, data fitting, regression, and signal processing. Originated with Gauss and Legendre (c. 1795–1805); pseudoinverse formalized by Moore (1920) and Penrose (1955).Given a (usually rectangular or rank-deficient) matrix and a vector , the system generally has no solution when (too many constraints) and infinitely many when (too few). The least squares method replaces the demand for an exact solution with the demand for the best approximate one: the that makes the residual as small as possible in Euclidean length. The Moore–Penrose pseudoinverse is the single matrix that, applied to , always returns the correct least-squares answer — and among all least-squares answers, the one of smallest norm. The surprising fact is that this one object simultaneously inverts square invertible matrices, solves overdetermined systems by projection, and solves underdetermined systems by minimum-norm selection — a unified generalization of matrix inversion that always exists and is unique.
The Core Insight
You cannot always solve , but you can always project onto the column space of and solve that. The residual of the best fit is perpendicular to everything can produce — this orthogonality is the whole theory in one geometric picture. The pseudoinverse is just the bookkeeping that makes "project, then solve, then pick the smallest" into a single matrix.
Formal Statement
The Least Squares Problem
Given and , the least squares problem is to find minimizing the squared Euclidean residual:
Symbols: is the design/coefficient matrix ( rows = equations, columns = unknowns); is the observation vector; is the parameter vector; is the residual; is the Euclidean norm.
The Normal Equations
Any minimizer of satisfies the normal equations:
Here is symmetric and positive semidefinite. If has full column rank (), then is invertible and the solution is unique:
The Moore–Penrose Pseudoinverse
The Moore–Penrose pseudoinverse of any is the unique matrix satisfying the four Penrose conditions:
The general least-squares / minimum-norm solution is then
Existence, Uniqueness, and Minimum Norm
For every and :
- A least-squares minimizer of always exists.
- The set of minimizers is — a single point iff has full column rank.
- Among all minimizers, is the unique one of smallest Euclidean norm .
Pseudoinverse via the SVD
If is a singular value decomposition with nonzero singular values , then
Why It Holds / Derivation
The Normal Equations from Orthogonality
Step 1. Define . Step 2. Differentiate with respect to :Carl Friedrich Gauss | 1777–1855
Gauss claimed to have used least squares as early as 1795 to fit astronomical and geodetic data, famously predicting the reappearance of the asteroid Ceres in 1801 after it was lost behind the Sun — by fitting an orbit to a handful of noisy observations. He published the method in Theoria Motus Corporum Coelestium (1809) and, crucially, gave it a probabilistic justification: least squares yields the most probable parameters when measurement errors follow what we now call a Gaussian (normal) distribution. This connection between minimizing squared error and maximizing likelihood under normal noise remains the deep reason squared error dominates statistics.
Building Intuition
Think of as a flat plane (or hyperplane) sitting inside . The vector is a point in space that, generically, floats off the plane — that's why has no solution. The best you can do is drop a perpendicular from straight down onto the plane; the foot of that perpendicular is , and the dropped segment is the residual , which by construction makes a right angle with the plane. "Least squares" literally means "shortest perpendicular," and the right-angle condition is the normal equations.
The pseudoinverse adds a second idea for the underdetermined case. If the plane is too big (many map to the same point), then once you've landed on the plane there are infinitely many "addresses" for the same destination — they differ by a null-space direction in which is blind. The pseudoinverse chooses the address closest to the origin, refusing to add any invisible null-space component. So does two clean geometric acts: project (kill the part of outside the column space) and trim (kill the part of inside the null space).
Least squares as orthogonal projection: b is projected onto the column space of A, leaving a perpendicular residual.
Worked Examples
Overdetermined: Fitting a Line Through Three Points
Given: Fit to data . Three equations, two unknowns.Underdetermined: Minimum-Norm Solution via Pseudoinverse
Given: One equation, two unknowns: , so , . Infinitely many solutions lie on a line; we want the smallest-norm point. Step 1 — for a full-row-rank wide matrix, .Common Misconceptions
Do not invert in practice. Forming and solving the normal equations [3] squares the condition number (), amplifying rounding errors badly when is ill-conditioned. Professional solvers use QR decomposition () or the SVD, which work directly with . The normal equations are pedagogically clean but numerically fragile. is not generally a true inverse. Only when is square and invertible does . In general and ; instead these are orthogonal projectors onto and respectively. Least squares is not invariant to rescaling variables or weighting equations. Consider doubling the second equation in a system: replacing row with leaves the exact solution set unchanged, but it changes the least-squares answer, because the squared residual of that equation now counts four times as heavily. Concretely, fitting to a constant gives ; if we instead believe the third point is twice as reliable and weight it doubly, shifts toward . Least squares optimizes the given metric — choosing the wrong weights silently distorts the fit. (This is why weighted least squares and generalized least squares exist.)Connections
Least squares sits at a crossroads of linear algebra, geometry, and statistics:
- Orthogonal Projection — where is the projector onto ; least squares is projection.
- Singular Value Decomposition — provides the universal formula [6] for and reveals how singular values control conditioning and stability.
- QR Decomposition — the numerically preferred route to via Gram–Schmidt or Householder reflections.
- Linear Regression — ordinary least squares is the statistical estimator; under Gaussian noise it is the maximum-likelihood and (Gauss–Markov) best linear unbiased estimator.
- Tikhonov Regularization (ridge regression) — replaces with to tame ill-posed problems.
- Four Fundamental Subspaces — the pseudoinverse maps bijectively and kills the orthogonal complements.
Real-World Applications
- Orbit determination & GPS — Gauss's original use; modern GPS receivers solve an overdetermined nonlinear least-squares problem (more satellites than the 4 unknowns: position + clock bias) to pin location to meters.
- Curve and surface fitting / CAD — fitting polynomials, splines, or planes to measured points in metrology and reverse engineering.
- Econometrics & statistics — ordinary least squares regression underlies essentially all empirical economics and the social sciences.
- Computer vision — camera calibration, homography estimation, and bundle adjustment minimize reprojection error, often a (nonlinear) least-squares problem.
- Machine learning — linear regression, the closed-form solution of ridge regression, and the normal equations seed gradient-based training; pseudoinverse appears in minimum-norm interpolation theory.
- Geodesy & seismic tomography — inverting noisy travel-time data for subsurface structure via regularized least squares, where tames rank-deficiency.
- Signal processing — Wiener filtering, system identification, and deconvolution all reduce to least-squares estimates of model parameters.
Historical Development
- 1795 — Gauss (age 18) reportedly uses least squares privately for geodetic computations, but does not publish.
- 1801 — Gauss recovers the lost asteroid Ceres by fitting an orbit to sparse observations, dramatically demonstrating the method's power.
- 1805 — Adrien-Marie Legendre publishes least squares first, in an appendix to Nouvelles méthodes pour la détermination des orbites des comètes, coining the term méthode des moindres carrés.
- 1809 — Gauss publishes Theoria Motus, claiming priority and adding the probabilistic (Gaussian-error) justification, igniting a priority dispute with Legendre.
- 1821–1823 — Gauss proves the Gauss–Markov theorem: least squares gives the best linear unbiased estimator regardless of the error distribution (given finite, equal variances).
- 1900–1909 — Erik Ivar Fredholm and others develop integral-equation analogues; foundations for generalized inverses laid.
- 1920 — E. H. Moore defines a "general reciprocal" (the pseudoinverse) for arbitrary matrices, in obscure notation that goes largely unnoticed.
- 1951 — Arne Bjerhammar independently rediscovers the generalized inverse in a geodesy context.
- 1955 — Roger Penrose gives the clean four-condition characterization [4] in "A generalized inverse for matrices," fusing the concept with modern matrix theory; the object becomes the Moore–Penrose pseudoinverse.
- 1965 — Golub & Kahan develop stable SVD algorithms, making pseudoinverse computation routine and numerically sound.
Subtleties & Limits
The pseudoinverse is discontinuous at points where the rank of changes: a tiny perturbation that lifts a zero singular value to makes jump by . This makes naive rank determination numerically delicate — how small is "zero"? — and motivates truncated SVD and regularization, which trade a little bias for vastly better stability. Choosing the truncation rank or the regularization parameter optimally (cross-validation, L-curve, discrepancy principle) is an active, problem-dependent art with no universal answer.
A deeper subtlety: squared error is optimal only under Gaussian noise. Real data with outliers or heavy tails make least squares non-robust — a single bad point can dominate. This drives ongoing research into robust regression (, Huber loss), sparse recovery (/LASSO, compressed sensing), and the broader question of which loss function the geometry of a given data-generating process actually warrants. The pseudoinverse answers the question definitively; for other norms there is no closed-form analogue.