What is a good way to find $\mathbf{x}\in\mathbb{R}^n$ that
- minimizes $\|A\mathbf{x}-\mathbf{b}\|^2$
- and subject to the above, minimizes $\|\mathbf{x}-\mathbf{x_0}\|^2$
where
- $A\in\mathbb{R}^{m\times n}$ (a sparse matrix, if it matters)
- $\textrm{rank}(A) = n-1$
- $m\approx4n$
?
If $A$ is invertible, then $$ x=A^{-1}b\tag1 $$ minimizes $\|Ax-b\|^2$ uniquely. However, in the question $A$ is not square and not even of full rank, it is not invertible.
If $A$ is not invertible, compute $P=AI_A$ where the columns of $P$ are a maximal independent subset of the columns of $A$. That is, $I_A$ has a single $1$ per column to pick out a single column from $A$. If the columns of $A$ are independent, then $I_A=I$ and $P=A$. In the question, $A$ has rank $n-1$, so $P$ and $I_A$ will have $n-1$ columns.
Since $$ \delta\|Pu-b\|^2=2\langle\overbrace{\color{#C00}{P^T(Pu-b)}}^{\color{#C00}{=0}},\delta u\rangle\tag2 $$ we have that $$ \begin{align} x_1 &=I_A\color{#C00}{u}\\ &=I_A\color{#C00}{\left(P^TP\right)^{-1}P^Tb}\tag3 \end{align} $$ minimizes $\|Ax-b\|^2$.
Let the columns of $N$ be linearly independent and span the null space of $A$ (i.e. $AN=0$). In the question, the null space has dimension $1$, so $N$ will have one column.
Since $$ \delta\langle x_1+Nu-x_0,x_1+Nu-x_0\rangle=2\langle\overbrace{\color{#C00}{N^T(x_1+Nu-x_0)}}^{\color{#C00}{=0}},\delta u\rangle\tag4 $$ we have that $$ \begin{align} x_2 &=x_1+N\color{#C00}{u}\\ &=x_1+N\color{#C00}{\left(N^TN\right)^{-1}N^T(x_0-x_1)}\\ &=\left(I-N\left(N^TN\right)^{-1}N^T\right)\underbrace{I_A\left(P^TP\right)^{-1}P^T\color{#090}{b}}_{x_1}+N\left(N^TN\right)^{-1}N^T\color{#090}{x_0}\tag5 \end{align} $$ minimizes $\|x-x_0\|^2$ given that $\|Ax-b\|^2$ is minimized.
Note that in the case where $A$ is invertible, we can take $I_A=I$, $P=A$, and $N(N^TN)^{-1}N^T=0$ to get $(1)$ as the result.