Find a sufficient and necessay condition on $I$ so that $\{M \in M_n(\mathbb R), \ rank(M) \in I \}$ is connected. Let $n \in \mathbb N$ and $ I \subset [| 1, n |]$. Find a necessary and sufficient condition on $I$ so that $\{M \in M_n(\mathbb R), \ rank(M) \in I \}$ is connected.
I know that $\{M \in M_n(\mathbb R), \ rank(M) =n\}$ is not connected since $\det$ is continuous while $\mathbb R^*$ is not connected.
Do you have a hint for this ? Thank you.
 A: Let $r<n$ and $Z_r=\{A\in M_n(\mathbb{R}); rank(A)=r\}$. . 
$\textbf{Proposition 1.}$ $Z_r$ is an arcwise connected set.
$\textbf{Proof.}$ Let $A\in M_n(\mathbb{R})$. Then $rank(A)=r$ iff there are $P=\begin{pmatrix}P_{r,r}&P_{r,n-r}\\P_{n-r,r}&P_{n-r,n-r}\end{pmatrix},Q=\begin{pmatrix}Q_{r,r}&Q_{r,n-r}\\Q_{n-r,r}&Q_{n-r,n-r}\end{pmatrix}$ invertible s.t. $A=Pdiag(I_r,0_{n-r})Q$. 
Note that $P_{r,n-r},P_{n-r,n-r}$ (second block column of $P$) and $Q_{n-r,r},Q_{n-r,n-r}$ (second block row of $Q$) are almost arbitrary. 
If $\det(P)<0$, then change the last column of $P$ with its opposite.If $\det(Q)<0$, then change the last row of $Q$ with its opposite. Then we may assume that $P,Q\in GL_n^+$, an arcwise connected set, and we are done. $\square$
$\textbf{Proposition 2.}$ Let $I$ be a subset of $[[0,n-1]]$ and $Z_I=\{A\in M_n(\mathbb{R}); rank(A)\in I\}$. Then $Z_I$ is an arcwise connected set. 
$\textbf{Proof.}$ Let $U,V$ s.t. $rank(U)=u<rank(V)=v$. There are two arcs that join $U,diag(I_u,0_{n-u})$ and $V,diag(I_v,0_{n-v})$ through $Z_u$ and $Z_v$. Moreover, the segment $t\in [0,1]\rightarrow (1-t)diag(I_v,0_{n-v})+tdiag(I_u,0_{n-u})$ is included in $Z_u\cup Z_v$.  $\square$
A: $GL_n(\mathbb{R})\cup\{A\}$ is connected where ${\rm det}\ A=0$
Proof : Fix $A$ with ${\rm det}\ A=0$.
If we use Jordan form, then $A= D+ N$ where $D$ is a diagonal. If
$D$ has $k$-zeros, for instance, $D={\rm diag} \
(0,\cdots,0,\ast,\cdots)$, then define $$
D_t=(t,|t|,\cdots,|t|,\ast,\cdots)$$
Then $A_t=D_t+N$ so that ${\rm det}\ A_t$ have positive and
negative.
Now assume that ${\rm det}\ A_t>0$ for $t>0$. By similar technique, we can show that $A$ is path conntected to some type matrix, for instance, ${\rm diag}(1,\cdots,1,-1,-1)$. By rotation, $A$ can be path connected to identity.
A: Hints.


*

*Denote the set of all rank-$k$ matrices by $R_k$. Then $\{M\in M_n(\mathbb R):\operatorname{rank}(M)\in I\}=\cup_{k\in I}R_k$.

*Every real square matrix admits a singular value decomposition over $\mathbb R$.

*$SO_n(\mathbb R)$ is pathwise connected to $I_n$.

*Denote any $r\times r$ zero matrix by $0_r$. Let $D=\operatorname{diag}(1,\ldots,1,\pm1)\in M_n(\mathbb R)$. If $S_k$ is a $k\times k$ positive diagonal matrix and $m$ is an integer such that $0\le m<n$ and $m\le k$, then $(S_k\oplus0_{n-k})D$ is path-connected to $\Lambda=\left(I_m\oplus0_{n-m}\right)D=I_m\oplus0_{n-m}$ on $R_m\cup R_k$.

