I want to use the method "completing squares" for this term:
$x^2-2xy +y^2+z^2*a+2xz-2yz$
The result should be $(x-y+z)^2 +(a-1)*z^3$
Is there a "recipe" behind how to do this? Hope someone could help
I want to use the method "completing squares" for this term:
$x^2-2xy +y^2+z^2*a+2xz-2yz$
The result should be $(x-y+z)^2 +(a-1)*z^3$
Is there a "recipe" behind how to do this? Hope someone could help
There is a method that is entirely algorithmic; it is Hermite's method done somewhat backwards, so that we diagonalize in the form $P^T M P = D,$ but $P$ is not orthogonal. Many books refer to this as "congruence," this should not be confused with similarity, which uses $R^{-1}M R.$
Your problem is just one step, $$ \left( \begin{array}{rrr} 1 & 0 & 0 \\ 1 & 1 & 0 \\ -1 & 0 & 1 \end{array} \right) \left( \begin{array}{rrr} 1 & -1 & 1 \\ -1 & 1 & -1 \\ 1 & -1 & A \end{array} \right) \left( \begin{array}{rrr} 1 & 1 & -1 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array} \right) = \left( \begin{array}{rrr} 1 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & A - 1 \end{array} \right) $$
This is of the form $P^T M P = D,$ as you can see. You actually want $Q^T DQ = M,$ which means we need $Q = P^{-1}.$ Since $\det P = 1$ and $P$ is upper triangular, this is not difficult, it is just the adjoint matrix, $$ Q = \left( \begin{array}{rrr} 1 & -1 & 1 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array} \right) $$ Reading rows from $Q,$ this means that your quadratic form is $$ 1 \cdot (x-y+z)^2 + (A-1) \cdot (z)^2 $$ which is what you wanted.
See reference for linear algebra books that teach reverse Hermite method for symmetric matrices
Aras' answer is really good. But you might be wondering how one develops intuition and what happens if one doesn't immediately see $x^2 - 2xy + y^2$ is a square. (Part of developing intuition is that this does become obvious.)
This'll get messy. But
So you have:
$\color {blue}{x^2}-2xy +y^2+z^2*a+2xz-2yz$
And you have an $x^2$ so we'll "complete" x first so take all the x terms and put them nearby.
$\color {blue}{x^2}\color {purple}{-2xy +2xz}+y^2+z^2*a-2yz$
We know that completing the square, the expression will need to start something like this: $x^2 \pm 2*x*something + ....$ so we factor out the $2x$
$\color {blue}{x^2 + 2x}\color {purple}{(z - y)}+y^2+z^2*a-2yz$
Now we know to "complete the square" we must do $x^2 \pm 2x*something \color{green}{+ something^2} \color {red}{- something^2} +...$
So
$\color {blue}{x^2 + 2x(z - y)} \color{green}{ + (z -y)^2} \color{red}{- (z -y)^2}+y^2+z^2*a-2yz=$
$\color {blue}{(x + (y -z))^2} \color{red}{- (z^2 - 2zy + y^2) }+y^2+z^2*a-2yz$
So let's clean up a little.
$\color {blue}{(x + y -z)^2} \color{red}{- z^2 + 2zy - y^2 }+y^2+z^2*a-2yz$
$\color {blue}{(x + y -z)^2} -z^2 +z^2*a$
So now we need to deal with just the $ ... - z^2 + z^2*a$. Well we factor out common terms.
$\color {blue}{(x + y -z)^2} +z^2(-1 +a)$
$\color {blue}{(x + y -z)^2} +z^2(a-1)$
There is no 'recipe', there's just practice which builds intuition.
Here the formula $x^2 - 2xy + y^2$ should immediately be noticible. You can write this as $(x-y)^2$. Furthermore, the $2xz - 2yz$ term can be factored to $2z(x-y)$. Thus your expression becomes
$$ (x-y)^2 + z^2 a + 2z(x-y)$$
Since you want to complete the square, you might notice that there is a $z^2$ term (with a constant $a$ in front of it but whatever for now), an $(x-y)^2$ term and a $2z(x-y)$ term. So by using a trick and writing $z^2 a = z^2 + z^2 (a-1)$ with the motivation of getting a $z^2$ term alone, we can write the expression as
$$ (x-y)^ 2 + z^2 + 2z(x-y) + (a-1)z^2$$
and completing the square yields
$$ (x-y + z)^2 + (a-1)z^2$$
which is the desired result.