Understanding the pseudoinverse calculator — concept and principle
This calculator computes the Moore–Penrose pseudoinverse A⁺ of any matrix, square or rectangular, together with its rank, its type and, if you enter a right-hand side b, the least-squares solution x = A⁺b and its residual. Use it for least-squares fitting, overdetermined or underdetermined systems, linear algebra courses, signal processing and robotics.
How it is calculated
- A⁺ is computed from the singular value decomposition A = UΣVᵀ as A⁺ = VΣ⁺Uᵀ, where Σ⁺ inverts the non-zero singular values and leaves the zeros as zeros.
- Special cases: A⁺ = A⁻¹ if A is invertible; A⁺ = (AᵀA)⁻¹Aᵀ if the columns are independent; A⁺ = Aᵀ(AAᵀ)⁻¹ if the rows are independent.
- Least squares: x = A⁺b, residual ‖Ax − b‖.
Singular values below a tiny relative tolerance are treated as zero. Simple fractions are shown exactly.
The principle
A rectangular or singular matrix has no ordinary inverse, but the pseudoinverse is the best substitute. It is the unique matrix satisfying the four Penrose conditions: AA⁺A = A, A⁺AA⁺ = A⁺, and both AA⁺ and A⁺A are symmetric. Through the SVD, A stretches along some directions and squashes others to zero; A⁺ undoes the stretching where it can and leaves the squashed directions at zero. As a result, x = A⁺b minimises ‖Ax − b‖, and among all minimisers it has the smallest length.
Worked example
Default: A = [1 1; 1 2; 1 3], b = (1, 2, 2). This fits a line y = c₀ + c₁t through (1, 1), (2, 2), (3, 2).
- The columns are independent, so rank = 2 and A⁺ = (AᵀA)⁻¹Aᵀ.
- AᵀA = [3 6; 6 14], its inverse = [7/3 −1; −1 1/2].
- A⁺ = [4/3 1/3 −2/3; −1/2 0 1/2], a 2 × 3 matrix.
- x = A⁺b = (4/3 + 2/3 − 4/3, −1/2 + 0 + 1) = (2/3, 1/2), so the line is y = 2/3 + t/2.
- Ax = (7/6, 5/3, 13/6); residual = √((1/6)² + (1/3)² + (1/6)²) ≈ 0.408248.
How to read the result
The rank tells you how much independent information A contains. "Full column rank" means a unique least-squares solution; lower rank means many solutions, and A⁺b picks the shortest one. A residual of 0 means b is exactly reachable; otherwise the residual is the smallest possible miss. For line fitting, x gives the intercept and slope.
Common mistakes
- Using (AᵀA)⁻¹Aᵀ when the columns are dependent; that inverse does not exist.
- Expecting AA⁺ to be the identity for a non-square matrix; it is only a projection.
- Thinking the pseudoinverse solves Ax = b exactly; it gives the least-squares answer.
- Ignoring tiny singular values, which can make results unstable.
Frequently asked questions
Is the pseudoinverse the same as the inverse?
Only for square invertible matrices. Otherwise it is a generalisation.
What size is A⁺?
If A is m × n, A⁺ is n × m.
Why use the pseudoinverse for regression?
x = A⁺b gives the ordinary least-squares coefficients, and the SVD route stays stable even when AᵀA is nearly singular.
Sources: Wolfram MathWorld, "Moore-Penrose Matrix Inverse" · J. Demmel, UC Berkeley Math 221 lecture notes, Lecture 3 (Fall 2011)