Finding $C$ such that $C^TAC=$diag$(I_k,-I_l,O)$ (Diagonal form) Let $A=\begin{pmatrix} 1 & 2 & 2 & 0 \\ 2 & 1 & 0 & 2 \\ 2 & 0 & 1 & 2 \\ 0 & 2 & 2 & 1 \end{pmatrix} \in M_4(\mathbb{R})$
I want to find a matrix $C$, such that $C^TAC=\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}$, since there are four eigenvalues, three positive and one negative.
I used the algorithm
reference for linear algebra books that teach reverse Hermite method for symmetric matrices
and got:
$D=\begin{pmatrix} 1 & 0 & 0 & 0 \\ -2 & 1 & 0 & 0 \\ \frac{2}{3} & -\frac{4}{3} & 1 & 0 \\ -\frac{8}{7} & \frac{2}{7} & \frac{2}{7} & 1 \end{pmatrix}$
So: $DAD^T=\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & -3 & 0 & 0 \\ 0 & 0 & \frac{7}{3} & 0 \\ 0 & 0 & 0 & \frac{15}{7} \end{pmatrix}$
But I want $C^TAC=\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}$
So I multiplied on the far left and far right by $\begin{pmatrix} 1 & 0 & 0 & 0 \\ -\frac{2}{\sqrt{3}} & \frac{1}{\sqrt{3}} & 0 & 0 \\ \frac{2}{3}\sqrt{\frac{3}{7}} & -\frac{4}{3}\sqrt{\frac{3}{7}} & \sqrt{\frac{3}{7}} & 0 \\  -\frac{8}{7}\sqrt{\frac{7}{15}} & \frac{2}{7}\sqrt{\frac{7}{15}} & \frac{2}{7}\sqrt{\frac{7}{15}} & 0 \end{pmatrix}$ and it's transpose, but the result isn't 
$\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}$.
So which matrix do I have to multiply on the far left and far right and how can I find such a matrix?

You’re well on the way to a solution, having done the hard part: you’ve found a matrix $D$ such that $DAD^T$ is a diagonal matrix. Now you just have to massage this diagonal matrix the desired form. There are two things that you’ll need to do, in either order: 


*

*Move the negative element on the diagonal down to the lower-right corner.

*Scale the diagonal elements so that they’re equal to $\pm1$.  


For the first of these tasks, look for a permutation matrix $P$ that will move the second column of a $4\times4$ matrix all the way to the right when you right-multiply by $P$. There are many choices, but a simple transposition will do the trick. Left-multiplying by $P^T$ will move the second row to the bottom, so the net effect on your diagonal matrix will be to move the negative element in the second row and column to the bottom right.  
For the second of these tasks, find another diagonal matrix $S$ such that both left- and right-multiplying by this matrix will scale the elements of your diagonal matrix appropriately.  
The matrix $C$ that you seek is the product of these two matrices and $D^T$, taken in an appropriate order.
