Lesson 12 of 15

Pseudoinverse

Moore-Penrose Pseudoinverse

The pseudoinverse A+A^+ generalises the matrix inverse to non-square and singular matrices. It gives the minimum-norm least-squares solution to Ax=bAx = b:

x=A+bx = A^+ b

For Full Column Rank (mnm \geq n, rank nn)

When AA has full column rank, the pseudoinverse is:

A+=(ATA)1ATA^+ = (A^T A)^{-1} A^T

This is exactly the least-squares formula.

For Square Invertible AA

A+=A1A^+ = A^{-1}

Example

A=(100100),ATA=(1001),A+=(ATA)1AT=AT=(100010)A = \begin{pmatrix} 1 & 0 \\ 0 & 1 \\ 0 & 0 \end{pmatrix}, \quad A^T A = \begin{pmatrix}1&0\\0&1\end{pmatrix}, \quad A^+ = (A^T A)^{-1} A^T = A^T = \begin{pmatrix}1&0&0\\0&1&0\end{pmatrix}

Your Task

Implement pseudoinverse(A) for matrices with full column rank using the formula A+=(ATA)1ATA^+ = (A^T A)^{-1} A^T. The helper inv_square handles both 1×1 and 2×2 square matrices.

Python runtime loading...
Loading...
Click "Run" to execute your code.