The set of all matrix with rank $n-1$ is a hypersurface. 
Prove that the set $M$ of $n\times n$ matrices with rank $n-1$ is a hypersurface in $\mathbb{R}^{n²}$ and find the tangent space at $A=(a_{ij})$ where $a_{ij}=\begin{cases}
 \delta_{ij} \ \text{if} \ (i,j)\neq(n,n) \\ 
 0 \ \ \ \text{if} \  (i,j)=(n,n)
\end{cases}$

The teacher left this problem along with others to study for the test (a graduate course in multivariable calculus).  If I find a function $f:\mathbb{R}^{n²} \rightarrow \mathbb{R}\in C^1$ such that $M=f^{-1}(c)$ and $grad \ f(x)\neq 0 \  (\forall x;f(x)=c$) do the problem becomes a merely computation but I can't find such function.
Can anybody help me?
Thanks in advance.
 A: Consider the determinant function $\det\colon \mathbb{R}^{n\times n} \to \mathbb{R}$.  I claim that an $n\times n$ matrix $A$ has rank $n-1$ if and only if


*

*$\det(A) = 0$, and 

*$A$ is a regular point of $\det$.
It follows that the set of such matrices is a smooth hypersurface.
To prove this, suppose first that $A$ has rank $n-1$.  Let $B$ be a nonsingular matrix whose entries are the same as $A$ except for one row.  Then
$$
\frac{d}{dt}\biggl[\det\bigl((1-t)A+tB\bigr)\biggr] \;=\; \frac{d}{dt}\biggl[(1-t)\det A + t \det B\biggr] \;=\; \frac{d}{dt}\biggl[t \det B\biggr] \;=\; \det B \;\ne\;0
$$
which proves that the directional derivative of $\det$ is nonzero in the direction of $B-A$.  (In the first step of the equation above, we have used the fact that determinant is linear with respect to each row of a matrix.)
For the converse, suppose that $A$ has rank less than $n-1$.  Then every collection of $n-1$ rows in $A$ are linearly dependent, so the determinant of $A$ remains $0$ if we change any one entry of $A$.  It follows that all $n^2$ partial derivatives of $\det$ are zero at $A$, so $A$ is a critical point for $\det$.
Finally, the tangent space to $M$ at the given matrix consists of all matrices $B=(b_{ij})$ for which $b_{nn}=0$, since changing $b_{nn}$ makes the matrix nonsingular, but changing any other entry of the matrix does not affect the determinant.
A: Halmos always said to understand something about linear algebra you should look at a $2\times 2$ matrix.  So let $n=2$ for now.  Let $f$ be the determinant function.
Let $A=\begin{pmatrix} a_{11} & a_{12} \\ a_{21} & a_{22}\end{pmatrix}$ and $X=\begin{pmatrix} x_{11} & x_{12} \\ x_{21} & x_{22}\end{pmatrix}$ be matrices.  Then
$$\begin{split}
    df_A(X) &= \left.\frac{d}{dt}\det(A + tX)\right|_{t=0} \\
            &= \left.\frac{d}{dt}\left((a_{11} + tx_{11})(a_{22} + tx_{22}) - (a_{12}+tx_{12})(a_{21}+tx_{21})\right)\right|_{t=0} \\
            &= a_{11} x_{22} + a_{22} x_{11} - a_{12} x_{21} - a_{21} x_{12}
\end{split}$$
This is equal to $\operatorname{tr}(\operatorname{adj}(A)X))$, where $\operatorname{adj}(A)$ is the adjugate matrix of $A$:
$$
\operatorname{adj}\begin{pmatrix} a_{11} &a_{12} \\ a_{21} &a_{22}\end{pmatrix}
= \begin{pmatrix} a_{22} & -a_{12} \\ -a_{21} & a_{11}\end{pmatrix}
$$
We claim that if $A$ is in $M$ (that is $\operatorname{rank}(A) =1$), then $df_A$ is not the zero map.  Indeed, let $X=\operatorname{adj}(A^T)$.  Then
$$
\operatorname{tr}(\operatorname{adj}(A)X)
= \operatorname{tr}\left(\begin{pmatrix} a_{22} & -a_{12} \\ -a_{21} & a_{11}\end{pmatrix}\begin{pmatrix} a_{22} & -a_{21} \\ -a_{12} & a_{11}\end{pmatrix}\right) = a_{11}^2 + a_{12}^2 + a_{21}^2 + a_{22}^2
$$
The only way this can be zero is if $A$ is the zero matrix, which, since it has rank one, it isn't.  This shows $M$ is a hypersurface.  It's not closed, because the closure would contain the zero matrix, a singular point.  
Now let $A = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}$.  The tangent space to $M$ at $A$ is the kernel of $df_A$.  If $X$ is any $2\times 2$ matrix,
$$
df_A(X) = \operatorname{tr}\left(\begin{pmatrix} 0 & 0 \\ 0 & 1 \end{pmatrix}\begin{pmatrix} x_{11} & x_{12} \\ x_{21} & x_{22} \end{pmatrix}\right) = \operatorname{tr}\begin{pmatrix} 0 & 0 \\ x_{21} & x_{22}\end{pmatrix} = x_{22}
$$
So the tangent space to $A$ is the set of matrices with bottom-right entry zero.
It is spanned by 
$$
\left\{\begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix},\begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix},\begin{pmatrix} 0 & 0 \\ 1 & 0 \end{pmatrix}\right\}
$$
If you read the wikipedia pages on Adjugate and Determinant you will see how this argument generalizes to larger matrices.  The derivative of the determinant map is the same.  If $A$ has rank $n-1$, you can cook up a matrix $X$ such that $df_A(X)$ is the sum of the squares of the $(n-1)\times(n-1)$ minors of $A$, which cannot be zero.  For the specific $A$, it should not be too hard to compute $df_A(X)$ in terms of the entries of $X$ and find a basis for its kernel.
A: Call $H \subset \mathbb{R}^{n^2}$ the set of matrices of rank $n-1$. Then the matrix $A$ of the OP belongs to $H$ (obvious). I claim that there is a neighborhood $U \subset \mathbb{R}^{n^2}$ of $A$ such that $U \cap H$ is a smooth hypersurface. To see this let $U$ to be the subset of matrices such that the minor $P$ given by the first $n-1$ rows and $n-1$ columns is different from zero. It is then clear that $U$ is open and $A \in U$. Consider now the restriction $f_U$ to $U$ of the function $f(X):= \det(X)$. Since the minor $P$ is not zero it is not difficult to check that the rank of the differential $df$ is 1 on the whole $U$. So the preimage $f_U^{-1}(0) = U \cap H$ is a hypersurface due to the implicit function theorem. To show that $H$ is a hypersurface at any member $B \in H$ just recall that if $B$ has rank $n-1$ then there are two invertible matrices $n \times n$, say $R,L$, such that $B = R A L$. Then the map $X \to R X L$ is a diffeomorphism of $\mathbb{R}^{n^2}$ which preserves $H$ and take the neighborhood $U$ of $A$, where $H \cap U$ is a hypersurface, to a neighborhood of $B$. So $H$ is also a hypersurface near $B$.  Thus $H$ is indeed a smooth hypersurface of $\mathbb{R}^{n^2}$. The tangent space $T_A H$ can be computed by using the derivative formula for the determinant. Namely, if $A(t)=(a_{ij}(t))$ is a smooth curve in $H$ through $A$ at $t=0$ we have $$\frac{d }{dt}\det A(t)|_{t=0} = \frac{d}{dt} a_{nn}(t)|_{t=0} = 0$$
Then the tangent space at $A$ is the set of all $n \times n$ matrix with zero in the $(n,n)$ entry.
Here is another proof that $H$ is a hypersurface without using the implicit function theorem. This proof is in the vein of algebraic geometry. Let $P_{ij}(X)$ be the minor of matrix $X \in \mathbb{R}^{n^2}$ obtained by removing row $i$ and column $j$. Let $U_{ij} := \{ X \in \mathbb{R^{n^2}} : P_{ij}(X) \neq 0 \} $ . Observe that $H \subset \cup_{ij} U_{ij} $. Now we are going to give a parametrization of $H \cap U_{ij}$ by expressing the entry $x_{ij} $ of $X$ as smooth function of the other entries. So take $X \in H \cap U_{ij}$ and notice that by Laplace expansion of $\det(X)$ along the $i$ row give us: $$0 = \det(X) = x_{ij} (-1)^{i+j} P_{ij}(X) + E(X) $$ 
where $E(X)$ is a polynomial in the entries of $X$ that not contains the entry $x_{ij}$. So $$x_{ij} = (-1)^{i+j+1} \frac{E(X)}{P_{ij}(X)} \, \, (*)$$
which shows that on each $H \cap U_{ij}$ is parameterized by a rational map $$\psi_{ij} : GL(n-1, \mathbb{R}) \times \mathbb{R}^{n-1} \times \mathbb{R}^{n-1} \to H$$ defined as follows. The matrix $\psi_{i,j}(A,v,w)$ reconstructed from $A$ to get all the rows and columns up to the rows $i,j$. the row $i$ up to the entry $i,j$ is the vector $v$ and the column $j$ is the vector $w$. Then the entry $x_{ij}$ is given by the above formula (*) by using $A,v,w$. Now should be clear that $H$ is indeed a hypersurface $\mathbb{R}^{n^2}$. 
