Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

 Open In Colab

In previous sections, we solved square matrix systems (nn equations, nn unknowns). But what if we have more equations than unknowns?

Ax=b\mathbf{A} \mathbf{x} = \mathbf{b}

where A\mathbf{A} is an m×nm \times n rectangular matrix (with m>nm > n). Such systems are called overdetermined (more equations than variables), and we usually cannot find a single solution x\mathbf{x} that perfectly satisfies every equation simultaneously. Instead, we can expand our notion of finding a solution to finding a best-fit.

Minimizing the Error

Define the residual, r\mathbf{r}, of the system as the difference between the left and right side of the equation:

r=Ax−b\mathbf{r} = \mathbf{A}\mathbf{x} - \mathbf{b}

If an exact solution existed, r=0\mathbf{r}=\mathbf{0} (the equation is satisfied for each element).

In lieu of an exact solution we can find one that minimizes all the elements of r\mathbf{r}, i.e. minimizes the quantity:

12r⋅r=12(Ax−b)T(Ax−b)\frac{1}{2} \mathbf{r} \cdot \mathbf{r} = \frac{1}{2} (\mathbf{A}\mathbf{x}-\mathbf{b})^T (\mathbf{A}\mathbf{x}-\mathbf{b})

where the factor of 12\frac{1}{2} is arbitrary but useful as seen below.

The Normal Equations

To find the minimum of our residul quantity 12r⋅r\frac{1}{2} \mathbf{r} \cdot \mathbf{r}, we take the derivative with respect to x\mathbf{x} and set it to zero:

12dr⋅rdx=0AT(Ax−b)=0(ATA)x=ATb\begin{aligned} \frac{1}{2} \frac{\mathrm{d} \mathbf{r} \cdot \mathbf{r}}{\mathrm{d}\mathbf{x}} &= 0 \\ \mathbf{A}^T (\mathbf{A}\mathbf{x} - \mathbf{b}) &= 0 \\ (\mathbf{A}^T \mathbf{A}) \mathbf{x} &= \mathbf{A}^T \mathbf{b} \end{aligned}

This final equation is called the Normal Equations. Notice that even though A\mathbf{A} is rectangular (m×nm \times n), the product (ATA)(\mathbf{A}^T \mathbf{A}) is always a square n×nn \times n matrix!

The Normal Equations linear system with a square matrix and can be solved using our usual toolkit for linear systems. However, we can go a step further.

The Moore-Penrose Pseudoinverse

Since (ATA)(\mathbf{A}^T \mathbf{A}) is a square matrix, we can invert it to solve for x\mathbf{x}:

x=(ATA)−1ATb\mathbf{x} = (\mathbf{A}^T \mathbf{A})^{-1} \mathbf{A}^T \mathbf{b}

We define the pseudoinverse, denoted A+\mathbf{A}^+, as:

A+=(ATA)−1AT\mathbf{A}^+ = (\mathbf{A}^T \mathbf{A})^{-1} \mathbf{A}^T

So our solution is simply x=A+b\mathbf{x} = \mathbf{A}^+ \mathbf{b}.

The pseudoinverse generalizes the inverse to rectangular matrices (both overdetermined and underdetermined). If the matrix actually is square and invertible, the pseudoinverse reduces mathematically to the standard exact inverse!

In practice, the ATA\mathbf{A}^T \mathbf{A} matrix, while square, is ill-conditioned. The pseudoinverse is calculated using a matrix decomposition called singular value decomposition, a generalization of eigendecomposition for rectangular matricies, which is more stable.

The number function is ‘np.linalg.pinv(A)’

Terminology

  • Consistent System: A system that has at least one exact solution satisfying all equations.

  • Inconsistent System: A system with solution that satisfies all equations simultaneously.

    • Overdetermined: More equations than unknowns (m>nm > n). Usually inconsistent. We use the pseudoinverse to find the best fit solution that minimizes the error.

    • Underdetermined: Fewer equations than unknowns (m<nm < n). Has an infinite number of solutions. The pseudoinverse finds the solution with the smallest magnitude: x⋅x\mathbf{x}\cdot \mathbf{x}.

Example: Consistent Overdetermined System

Let’s look at a system with 3 equations but only 2 variables.

(1) 20c+50t=70020 c + 50 t = 700
(2) c+t=20c + t = 20
(3) 50c+20t=70050 c + 20 t = 700

(2050115020)(ct)=(70020700)\begin{pmatrix} 20 & 50 \\ 1 & 1 \\ 50 & 20 \end{pmatrix} \begin{pmatrix} c \\ t \end{pmatrix} = \begin{pmatrix} 700 \\ 20 \\ 700 \end{pmatrix}

Since it’s still a linear system, lets inspect this graphically:

Example: Inconsistent Overdetermined System

Usually, 3 lines will not cross at exactly the same point.

(1) 2c+t=152 c + t = 15
(2) c+−t=10c + -t = 10
(3) c+2t=14c + 2 t = 14

The solution found by the pseudoinverse minimizes the perpendicular distance from the point to all three lines simultaneously. It mathematically finds the “center of mass” of the intersection triangle!

Example: Inconsistent overdetermined system with linearly dependent rows

Let’s look at one more inconsistent system.

(1) 2c+t=152 c + t = 15
(2) c+−t=10c + -t = 10
(3) 2c+1t=102 c + 1 t = 10

Now two equations are parallel (but not overlapping).

Example: Inconsistent underdetermined system

Consider if we only had one equation but two unknowns!

(1) 2c+t=152 c + t = 15

Let’s see what ‘solution’ the pseudoinverse finds!

Conditioning of a Rectangular Matrix

Just as we saw with square matrices, we can calculate the condition number of a rectangular matrix to understand how sensitive our best-fit solution is to noise in the data b\mathbf{b}.

We simply extend the definition using the pseudoinverse:

cond(A)=∥A∥∥A+∥\text{cond}(\mathbf{A}) = \|\mathbf{A}\| \|\mathbf{A}^+\|

Modern approach to pseduoinverse calculation

Baring a few special cases, the pseudoinverse is most efficiently solved through Singular Value Decomposition (the generalization of eigen-decomposition for rectangular matricies.)