# Diagonal matrices and the non-zero eigenvalues

If I have 2 congruent $n\times n$ matrices $A,B$ both diagonalized with all non-zero eigenvalues and the eigenvalues are ordered in descending order down the diagonal. $a$ is the number of positive eigenvalues of $A$ and $b$ that of $B$. What then is the must the $a=b$? I know that there is a theorem that says it is so, but I am not allowed to use that. I am supposed to argue by congruence.

Thank you.

-

I will show this for the $2 \times 2$ case by explicitly doing the matrix multiplication. You can either generalise this to the $n \times n$ case yourself, or wait for someone with a more elegant answer.
Matrices $A$ and $B$ are congruent, i.e. there exists an invertible matrix $P$ such that: $$P^{T}AP = B.$$ Write out the elements of the matrices and perform the matrix multiplication, i.e. $$\left( \begin{array}{cc} p_{11} & p_{21} \\ p_{12} & p_{22} \end{array}\right)\left( \begin{array}{cc} a_{11} & 0 \\ 0 & a_{22} \end{array}\right)\left( \begin{array}{cc} p_{11} & p_{12} \\ p_{21} & p_{22} \end{array}\right) = \left( \begin{array}{cc} b_{11} & 0 \\ 0 & b_{22} \end{array}\right),$$ $$\left( \begin{array}{cc} p_{11}^{2}a_{11} + p_{21}^{2}a_{22} & p_{11}p_{12}a_{11} + p_{21}p_{22}a_{22} \\ p_{11}p_{12}a_{11} + p_{21}p_{22}a_{22} & p_{12}^{2}a_{11} + p_{22}^{2}a_{22}\end{array}\right) = \left( \begin{array}{cc} b_{11} & 0 \\ 0 & b_{22} \end{array}\right).$$ To satisfy this equation let $p_{12} = p_{21}= 0$. In this case $b_{jj} = a_{jj}p_{jj}^{2}$, i.e. the signs of the $j$-th entries in $A$ and $B$ are the same.