TITLE: Matrix multiplied by its pseudo-inverse doesn't give the identity matrix. Why?
QUESTION [5 upvotes]: Using Matlab, I randomly generate matrix $A \in \Bbb C^{2 \times 1}$ and compute its pseudo-inverse $A^{+}$. I notice that $AA^{+} \neq I$, and yet $\mbox{Tr}(AA^{+}) = 1$.
For other sizes it seems like the trace is equal to the smaller dimension of $A$. I couldn't find this property explained. Could anyone help me understand these two facts?

REPLY [4 votes]: Let $A \in \Bbb C^{m \times n}$ and $r := \mbox{rank} ({\rm A})$. Let the singular value decomposition (SVD) of $\rm A$ be
$${\rm A} = \begin{bmatrix} {\rm U}_1 & {\rm U}_2\end{bmatrix} \begin{bmatrix} \Sigma_1 & {\rm O}\\ {\rm O} & {\rm O}\end{bmatrix} \begin{bmatrix} {\rm V}_1^*\\ {\rm V}_2^*\end{bmatrix}$$
where $\Sigma_1$ is the $r \times r$ diagonal matrix whose diagonal entries are the positive singular values of $\rm A$. Note that $\rm A$ is invertible — assuming it is not empty, of course. Hence, the pseudo-inverse of $\rm A$ is
$${\rm A}^+ = \begin{bmatrix} {\rm V}_1 & {\rm V}_2\end{bmatrix} \begin{bmatrix} \Sigma_1^{-1} & {\rm O}\\ {\rm O} & {\rm O}\end{bmatrix} \begin{bmatrix} {\rm U}_1^*\\ {\rm U}_2^*\end{bmatrix}$$
and
$${\rm A} {\rm A}^+ = \begin{bmatrix} {\rm U}_1 & {\rm U}_2\end{bmatrix} \begin{bmatrix} {\rm I}_r & {\rm O}\\ {\rm O} & {\rm O}\end{bmatrix} \begin{bmatrix} {\rm U}_1^*\\ {\rm U}_2^*\end{bmatrix} = {\rm U}_1 {\rm U}_1^*$$
is a projection matrix. Note that ${\rm A} {\rm A}^+ = {\rm U}_1 {\rm U}_1^* = {\rm I}_m$ if and only if matrix $\rm A$ has full row rank. Moreover, the trace is
$$\mbox{tr} \left( {\rm A} {\rm A}^+ \right) = \mbox{tr} \left( {\rm U}_1 {\rm U}_1^* \right) = \mbox{tr} \left( {\rm U}_1^* {\rm U}_1 \right) = \mbox{tr} \left( {\rm I}_r \right) = r = \mbox{rank} ({\rm A})$$
Let $\rm P$ be a projection matrix. Then, $\mbox{tr} \left( {\rm P} \right) = \mbox{rank} ({\rm P})$.  A very nice property of projection matrices.