Rank of $X-\operatorname{diag}{(X)}$ when $X$ is a rank $k$ Positive-semidefinite matrix? Assume $X\in\mathbb{R}^{n\times n}$ is a positive semidefinite matrix with Rank($X$)=$k$ and all eigenvalues are real, what can we say about the rank of $X-\operatorname{diag(X)}$? In other words, how does the rank of $X$ change if we set all its diagonal elements to zeros? 
 A: Denote the off-diagonal part of a positive semidefinite matrix $X$ by $f(X)$. Let $k=\operatorname{rank}(X)$ and $r=\operatorname{rank}(f(X))$. If $k=0$ (i.e. if $X=0$), clearly $r$ must be zero. Suppose $k\ge1$. By considering the $2\times2$ principal submatrices of $X$ and $f(X)$, we see that $r\ne1$. However, we argue that $r$ can be any integer but $1$ between $0$ and $n$.
Let $E_n$ and $0_n$ denote respectively the all-one matrix and the zero matrix of size $n$. For any pair of integers $(a,b)$ with $1\le a\le b\ne1$, let
$$
D_{ab}=E_b+(I_{a-1}\oplus0_{b-a+1})\in M_b(\mathbb R).
$$
Then $D_{ab}$ is positive semidefinite, $\operatorname{rank}(D_{ab})=a$ and $\operatorname{rank}(f(D_{ab}))=b$. Now, for any pair of nonnegative integers $k\ge1$ and $r\ne1$, if we put
$$
X=
\begin{cases}
D_{kr}\oplus 0_{n-r}&\text{ when } 0<k<r\ne1,\\
D_{rr}\oplus I_{k-r}\oplus 0_{n-k}&\text{ when } k\ge r\ge2,\\
I_k\oplus 0_{n-k}&\text{ when } k>r=0.
\end{cases}
$$
then $X$ is positive semidefinite matrix, $\operatorname{rank}(X)=k$ and $\operatorname{rank}(f(X))=r$.
