Relation between rank and number of distinct eigenvalues [duplicate]

$$3 \times 3$$ matrix B has eigenvalues 0, 1 and 2. Find the rank of B.

I understand that $$0$$ being an eigenvalue implies that rank of B is less than 3.

The solution is here (right at the top). It says that rank of B is 2 because the number of distinct non zero eigenvalues is 2.

This thread says that the only information that the rank gives is the about the eigenvalue $$0$$ and its corresponding eigenvectors.

What am I missing?

Edit
What I am really looking for is an explicit answer to this:

"Is the rank of a matrix equal to the number of distinct non zero eigenvalues of that matrix?"
Yes/No/Yes for some special cases

Take for example the matrix $A= \begin{bmatrix} 1 & 0 & 0 \\ 0 & 2 & 0 \\0 & 0 & 0 \end{bmatrix}$, its rank is obviously $2$, eigenvalues are distinct and are $0,1,2$.
We have theorem which says that if eigenvalues are distinct then their eigenvectors must be linearly independent, but the rank of the matrix is $n-1$ if one of this eigenvalues is zero.

Edit after question edit

To answer more generally we need Jordan forms.

Let $A$ be $n$-dimensional square matrix with $n-k$ non-zero eigenvalues
(I don't make here a distinction between all different values and repeated- if all are distinct then there are $n-k$ values , if some are with multiplicities then summarize their number with multiplicities to make full sum $n-k$) and $k$ zero eigenvalues.

Express $A$ through similarity with the Jordan normal form $A=PJP^{-1}$. The matrix $J$ can be presented as composition $J= \begin{bmatrix} J_n & 0 \\0 & J_z \end{bmatrix}$ where $J_n$ is a square part of Jordan matrix with $n-k$ non-zero values (which are eigenvalues) on diagonal and $J_z$ is a square part of Jordan matrix with $k$ zero values on its diagonal.

It is clear that because on the diagonal of upper-triangular matrix $J_n$ are non-zero values and the determinant as the product of these values is non-zero so $J_n$ has full rank i.e. $n-k$.

The rank of $J_z$ depends on the detailed form of this matrix and it can be from $0$ (when $J_z=0$) to $k-1$ ( see examples in comments). It can't be $k$ because $J_z$ is singular.

Therefore the final rank of $J$ can be from $n-k$ to $n-1$.
Similarity preserves rank so the rank of $A$ can be also from $n-k$ to $n-1$.

• Thank you for answering! If an eigen value is zero, i know that A has rank< 3, but how do I know for sure its '2' and not '1', or in general, n-2 or n-3 etc... Jun 29, 2017 at 11:56
• Because it has two dinstinct non-zero eigenvalues in this case. Jun 29, 2017 at 11:59
• I think I see it. This was my problem: how do I know for sure there is only one independent eigen vector with the eigen value 0. for example,if there's two vectors with eigen val=0, the rank of A would be 1. Since these are vectors in $R^3$ , there can be atmost 3 independent vectors, and we have 3 distinct eigen values giving 3 independent eigen vectors. So I can be certain that the eigen value 0 has only one vector. Jun 30, 2017 at 8:01
• have I got it right? Jun 30, 2017 at 8:02
• $A= \begin{bmatrix} 1 & 0 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 & 0\\0 & 0 & 1 & 0 & 0 \\0 & 0 & 0 & 0 & 0 \\0 & 0 & 0 & 0 & 0\end{bmatrix}$, $\ \ \ \text{rank}{\ 3}$. $\ \ \ \$ $B= \begin{bmatrix} 1 & 0 & 0 & 0 & 0\\ 0 & 1 & 0 & 0 & 0\\0 & 0 & 1 & 0 & 0 \\0 & 0 & 0 & 0 & 1 \\0 & 0 & 0 & 0 & 0\end{bmatrix}$, $\ \ \text{rank}{\ \ \ 4}$ - they have the same characteristic polynomial $\lambda^2(\lambda -1)^3$. Experiment with other this type matrices at wims.unice.fr/~wims/en_tool~linear~matrix.en.phtml. Jun 30, 2017 at 8:27

If the linear transformation has eigen-vectors with distinct eigenvalues, then they are linearly independent(check it, it's easy). Therefore, we know that $\lambda_1u$, $\lambda_2v\in Im(T)$, where $u$ and $v$ are the eigenvectors. Since they are non-zero and linearly independent (the fact that they are multiplied by constants does not change it) we know that $dim(Im(T)) \geq 2$.

• Thanks for answering! It looks like you are talking about the dimension and rank of the span of eigen vectors, and not the matrix itself? (please check the edit to my question) Jun 29, 2017 at 11:54
• No, the rank is the dimension of the image of a linear transformation(what you call a matrix), therefore, when I find the vectors $lambda_1u$ and $lambda_2v$ in the image, I have found two linearly independent vectors in it. This means that the dimension of the image (rank) is at least two. But because zero is an eigenvalue, we know that the kernel has dimension one. From the theorem of kernel and image($dim(V) = dim(Ker(T))+dim(Im(T))$), we conclude rank = 2. Jun 29, 2017 at 12:33
• I was wondering how the kernel of $T$ is 1-dimensional... We know $0$ is an eigenvalue but multiple eigenvectors could be associated with it. I guess $T$ can have a maximum of $n$ linearly independent eigenvectors (2 of them already associated with the distinct eigenvalues and so only one left to associate with $0$) Jan 21, 2021 at 14:51

Because the eigenvalues are distinct, eigenvectors are distinct, and there is a eigen-space spanned by them. The resulting matrix is $$\begin{bmatrix} 0 &0 &0 \\ 0 &1 &0 \\ 0 &0 &2 \\ \end{bmatrix}$$ And the rank is 2. A rank is the dimension of space spanned by all image in current space.

• Thanks for answering! I'm not sure what is 'image' or 'current space', but it looks like you are talking about the dimension and rank of the span of eigen vectors, and not the matrix itself? (please check the edit to my question) Jun 29, 2017 at 11:51