Consider a quadratic form $$f(x) = \sum_{i=1}^{n}a_i x_i ^2$$ $f$ represents $0$ non-trivially. Then I need to show that by a linear change of variables, I can get the following quadratic form $$f(y) = \sum_{i=1}^{n-2}b_i y_i ^2 - 2 b_ny_{n-1}y_n$$
Now as suggested in Find a change in variable that will reduce the quadratic form to a sum of squares by Gerry Myerson, I put $x = Py$ , for some $n \times n$ matrix $P$. Then $$f(x)=f(Py)=(Py)^tAPy=y^t(P^tAP)y$$ My question is how do I find the matrix $P$ s.t. I get $f(y)$ as mentioned above.
I do not have a complete answer, just some ideas. If we take: $$ B = \begin{bmatrix} b_{1} & 0 & 0 & 0 & 0 \\ 0 & \ddots & \vdots & \vdots & \vdots \\ 0 & & b_{n-2} & 0 & 0\\ 0 & \dots & 0 & 0 & -b_n \\ 0 & \dots & 0 &-b_n & 0 \end{bmatrix} $$
then $f(y) = \sum_{i=1}^{n-2}b_i y_i ^2 - 2 b_ny_{n-1}y_n = y^{t} B y $. So we are interest in finding an invertible matrix $P$ such that $P^{t} A P = B$ with $A=\text{diag}(a_1, a_2, \dots a_{n-1})$.
Since $B$ is symmetric with set of eigenvalues $\text{spec}(B)=\{ b_1, b_2, \dots b_{n-2}, \pm b_n \}$, there exists an orthogonal matrix $Q$ such that $$ B=QDQ^{t} $$ where $D=\text{diag}(b_1, b_2, \dots b_{n-2}, \pm b_n)$. Hence we must find $P$ such that:
$$ P^{t}AP=QDQ^{t} \Longrightarrow D=(PQ)^{t}A(PQ). $$ Where in the last equation all matrices are known exept $P$, but we must find a clever idea for computations. Hope this helps.