Transform $f(x_1,x_2,x_3)=2{x_1}^2+5{x_2}^2+5{x_3}^2+4x_1x_2-4x_1x_3-8x_2x_3$ to a diagonal form. I try to transform Transform $$f(x_1,x_2,x_3)=2{x_1}^2+5{x_2}^2+5{x_3}^2+4x_1x_2-4x_1x_3-8x_2x_3$$ to a diagonal form. I can do it using eigenvalue, but when I directly complete the square to find its diagonal form, I failed. And my textbook tell me that every formula like this can be transformed into diagonal form by completing the square. 
I have been working this for hours, please help me.
 A: Every book on quadratic forms has Hermite's method in one or another disguise. It is easy. First we take care of all terms that contain $x_1.$
$$ 2 (x_1 + x_2 - x_3)^2 = 2 x_1^2 + 2 x_2^2 + 2 x_3^2 - 4 x_2 x_3 -4 x_3 x_1 + 4 x_1 x_2.   $$
$$   f - 2 (x_1 + x_2 - x_3)^2 = 3 x_2^2  - 4 x_2 x_3 + 3 x_3^2$$
Next we take care of all remaining terms that contain $x_2.$
$$  3 \left(x_2 - \frac{2}{3} x_3 \right)^2 = 3 x_2^2 - 4 x_2 x_3 + \frac{4}{3} x_3^2$$
$$   f - 2 (x_1 + x_2 - x_3)^2 -  3 \left(x_2 - \frac{2}{3} x_3 \right)^2 = \frac{5}{3} x_3^2  $$
As you see, all that is left involves only $x_3$ and is (must be) a multiple of $x_3^2.$
$$   f = 2 (x_1 + x_2 - x_3)^2 +  3 \left(x_2 - \frac{2}{3} x_3 \right)^2 + \frac{5}{3} x_3^2  $$
A: \begin{align}
2x_1^2 + 5x_2^2+5x_3^2 + 4x_1x_2-4x_1x_3-8x_2x_3 = \\
2\left( x_1^2+2x_1x_2-2x_1x_3-2x_2x_3\right) + 5x_2^2+5x_3^2 - 4x_2x_3 = \\
2 \left( x_1^2 + x_2^2 + x_3^2 + 2x_1x_2 - 2x_1x_3 - 2x_2x_3\right) + 3x_2^2 + 3x_3^2 - 4x_2x_3 = \\
2(x_1 + x_2 - x_3)^2 + 3 \left (x_2^2 - \frac 43 x_2x_3 + \frac 49 x_3^2 \right ) - \frac 43 x_3^2 + 3x_3^2 = \\
2\left( x_1 + x_2 - x_3\right)^2 + 3 \left( x_2  - \frac 23 x_3\right )^2 + \frac 53 x_3^2
\end{align}
A: I'm not sure if this is what you want, but we can note that $$2x_1^2+4x_1x_2-4x_1x_3=2x_1(x_1+2(x_2-x_3)),$$ which we can instead write as $$2(x_1+(x_2-x_3)-(x_2-x_3))(x_1+(x_2-x_3)+(x_2-x_3)),$$ or as $$2(x_1+x_2-x_3-(x_2-x_3))(x_1+x_2-x_3+(x_2-x_3)).$$ Applying the difference of squares formula and distributing the $2$ yields $$2(x_1+x_2-x_3)^2-2(x_2-x_3)^2=2(x_1+x_2-x_3)^2-2x_2^2-2x_3^2+4x_2x_3.$$ Hence, by substitution and gathering like terms, we have $$f(x_1,x_2,x_3)=2(x_1+x_2-x_3)^2+3x_2^2-4x_2x_3+3x_3^2.$$ Note that from this point, we could apply yet another instance of the difference of squares formula in the other direction, and obtain a factorization of $f.$ However, I suspect that instead, you'd rather observe that $3x_2^2-4x_2x_3$ can be rewritten (in a similar fashion to the work above) as $$3\left(x_2-\frac23x_3+\frac23x_3\right)\left(x_2-\frac23x_3-\frac23x_3\right),$$ whence we can show (again, similarly to the work above) that $$3x_2^2-4x_2x_3=3\left(x_2-\frac23x_3\right)^2-\frac43x_3^2,$$ and so $$f(x_1,x_2,x_3)=2(x_1+x_2-x_3)^2+3\left(x_2-\frac23x_3\right)^2+\frac53x_3^2.$$ Finally, putting $$\bar x_1=\sqrt2(x_1+x_2-x_3),\\\bar x_2=\sqrt3\left(x_2-\frac23x_3\right),\\\bar x_3=\sqrt{\frac53}x_3,$$ we have $$f(x_1,x_2,x_3)=\bar x_1^2+\bar x_2^2+\bar x_3^2.$$
So, there you have it. Completing the square does allow us to rewrite it in the desired fashion. However, it's rather tedious, and it's far more preferable to use slicker, quicker tricks.
A: Do you know about the Gaussian method? It goes like this:
$$f(x_1,x_2,x_3) = 2\left[x_1^2 + \frac52 x_2^2 + \frac52 x_3^2 + 2x_1x_2 - 2x_1 x_3 - 8x_2 x_3 \right] \\ =2\left[ (x_1 ^2 + 2x_1x_2 \color{red}{+ x_2^2}) \color{red} {- x_2^2} + \frac52x_2^2 + \frac52x_3^2 - 2x_1x_3 -8x_2x_3 \right] \\ = 2\left[ (x_1 + x_2)^2 + ...\right]$$
You keep on doing that, and eventually put: $y_1 = x_1 + x_2$, etc.
