TITLE: how to solve a system with more equations than unkowns?
QUESTION [7 upvotes]: In general, how do you solve a system with more equations than unknowns? I know that if I select the equations to match them with the number of unknowns, there may be zero or many solutions depending on our selection. Where can I go from there? And how does a "pseudo inverse" come in the picture? Thank you. -Cody
EDIT: I know overdetermined system usually have no solution, but in my case (triangulation matting, i.e filtering out the weatherman from the blue screen), I was told there is a solution and I need to find it using pseudo inverse.

REPLY [2 votes]: Consider the sample problem
$$
\begin{align}
 \mathbf{A} x &= b \\
%  A
\left[
\begin{array}{cc}
 1 & 0 \\
 0 & 0 \\
\end{array}
\right]
%  x
\left[
\begin{array}{c}
 x_{1} \\
 x_{2}
\end{array}
\right]
%
&=
%  x
\left[
\begin{array}{c}
 b_{1} \\
 b_{2} \\
\end{array}
\right]
%
\end{align}
$$
If $b_{1}\ne 0$, a solution exists. If $b_{2} = 0$, the solution is unique:
$$
 x = 
\left[
\begin{array}{c}
 x_{1} \\
 x_{2}
\end{array}
\right]
=
\left[
\begin{array}{c}
 b_{1} \\
 0
\end{array}
\right]
$$
Let's focus on the least squares case where $b_{1}\ne 0$, and $b_{2}\ne 0$. The least squares minimizers are defined as
$$
 x_{LS} = \left\{
x \in \mathbb{C}^{2} \colon
\lVert
 \mathbf{A} x - b
\rVert_{2}^{2}
\text{ is minimized}
\right\}
$$
The solution to the least squares problem is
$$
 x_{LS} = \color{blue}{\mathbf{A}^{\dagger} b} +
\color{red}{\left(
  \mathbf{I}_{2} - \mathbf{A}^{\dagger}\mathbf{A}
\right) y}, \qquad
y \in \mathbb{C}^{2}.
$$
Coloring separates $\color{blue}{range}$ spaces from $\color{red}{null}$ spaces. The diagram shows the point $ \color{blue}{\mathbf{A}^{\dagger} b}$ in the range space $\color{blue}{\mathcal{R}\left(\mathbf{A}\right)}$. The full solution is the affine space represented by the dashed red line.

The least squares solution for the example is
$$
 x_{LS} = 
\color{blue}{
\left[
\begin{array}{c}
 b_{1} \\
 0
\end{array}
\right]
}
+
\alpha
\color{red}{
\left[
\begin{array}{c}
 0 \\
 1
\end{array}
\right]
}, \qquad \alpha \in \mathbb{C}
$$