Least Squares Solver using SVD and the Pseudoinverse

Compute the least squares solution $\mathbf{x} = A^{\dagger}\mathbf{b}$ using the Moore-Penrose pseudoinverse.
Most robust method for rank-deficient and ill-conditioned matrices.

The SVD-based method uses the pseudoinverse to solve least squares problems:

$ \mathbf{x} = A^{\dagger}\mathbf{b} $

How it works:

Compute SVD: $A = U\Sigma V^T$, then form the pseudoinverse:

$ A^{\dagger} = V\Sigma^{\dagger}U^T $

where $\Sigma^{\dagger}$ inverts nonzero singular values and transposes.

Advantages:

  • Handles rank-deficient matrices automatically
  • Most numerically stable method
  • Provides minimum-norm solution for underdetermined systems
  • Reveals condition number and numerical rank
Rows $m$: Columns $n$:
Final Output as:
© 2025 Shelvean Kapita: kapita@tamu.edu
All code released under the MIT License.
Last modified: December 18, 2025