non-similar solution of matrix equations Let $X$ be an $n\times n$ matrix. I want to know how many non-similar solutions does the equation $X^2=X$ have and what is the form of solutions?
 A: Consider the eigenvalues of $X$. The only possible eigenvalues are $0$ and $1$. This is due to the fact for any eigenvector $v$ with eigenvalue $\lambda$, $\lambda v=Xv=X^2v=\lambda^2v$.
Note that since $(I-X)X=0$, it follows that $\text{nullity}(I-X)\geq\text{rank}(X)$, as the linearly independent columns of $X$ are in the nullspace of $I-X$. Also, the columns of $I-X$ and the columns of $X$ together span $\mathbb{R}^n$, so $\text{rank}(I-X)+\text{rank}(X)\geq n$.
Hence, it follows combining the above results and using rank-nullity theorem, we get $\text{nullity}(I-X)+\text{nullity}(X)=n$.
Since, $\dim(E_1)=\text{nullity}(I-X)$ and $\dim(E_0)=\text{nullity}(X)$, (where $E_\lambda$ is the eigenspace associated to the eigenvalue $\lambda$), we have $n$ linearly independent eigenvectors.
Hence, $X$ is diagonalisable, so it is similar to a diagonal matrix, specifically the diagonal matrix:
$$\left(\begin{matrix}I_{\text{rank}(X)}&0\\0&0_{\text{rank}(I-X)\times\text{rank}(I-X)}\end{matrix}\right)$$
As similarity of matrices is an equivalence relation, we note that the idempotent matrices of the same rank and size are similar.
Hence now, it suffices to show that is at least one idempotent matrix of each rank from $0$ to $n$ of size $n$. Consider:
$$X=\left(\begin{matrix}I_r&0\\0&0_{(n-r)\times(n-r)}\end{matrix}\right)$$
It is clearly of rank $r$ and is idempotent. Hence for each $0\leq r\leq n$, we get one solution to the equation which is not similar to the previous solutions, hence we have $n+1$ solutions to the equation which are not similar.
