# How to solve this equation with matrix rank condition

It is known that quadratic form $$f\left(x_{1}, x_{2}\right)=x_{1}^{2}-4 x_{1} x_{2}+4 x_{2}^{2}$$ can be transformed into quadratic form $$g\left(y_{1}, y_{2}\right)=a y_{1}^{2}+4 x_{1} x_{2}+6 y_{2}^{2}$$ by orthogonal transformation (It is known that matrix $$\left(\begin{array}{ll} a & 2 \\ 2 & b \end{array}\right)$$ and matrix $$\left(\begin{array}{ll} 1 & -2 \\ -2 & 4 \end{array}\right)$$ are congruent matrices under orthogonal transformation).

Now I want to find the value of a, b.

  Solve[Det[{{a, 2}, {2, b}}] == Det[{{1, -2}, {-2, 4}}] &&
MatrixRank[{{a, 2}, {2, b}}] == MatrixRank[{{1, -2}, {-2, 4}}], {a,
b}]


But the above code returns an empty set after being run (the answer is {a->4,b->1}). What can I do to solve this matrix equation?

Updated content:

In addition, for the three-dimensional case, how to find the solution of the following matrix equation quickly:

Q = Array[x, {3, 3}];
A = {{1 - a, 1 + a, 0}, {1 + a, 1 - a, 0}, {0, 0, 2}} /. a -> 2;
FindInstance[
Thread[Transpose[Q] . A . Q == {{-4, 0, 0}, {0, 2, 0}, {0, 0, 2}}],
Flatten[Q], Reals]


Since Q is required to be a real matrix, the above code has been running and cannot return results.

Other examples for testing:

A = {{a, 0, 1}, {0, a, -1}, {1, -1, a - 1}};
Transpose[Q] . A . Q == {{1, 0, 0}, {0, 1, 0}, {0, 0, 0}}

• Should the two matrices have the same eigenvalues? If so, that would give two relatively simple equations. I don't think that your equations have a finite solution set. – mikado Aug 3 at 5:01
• @mikado Yes, two contract matrices under orthogonal transformation are also similar to each other. But I want to solve this matrix equation directly without any skill. – A little mouse on the pampas Aug 3 at 5:10
• "I want to solve this matrix equation directly without any skill." -- Oh. Otherwise, I would have suggested that you use A = {{a, 2}, {2, b}}; B = {{1, -2}, {-2, 4}}; Solve[{Det[A] == Det[B], Tr[A] == Tr[B]}, {a, b}] instead. Two symmetric $2 \times 2$ matrices have the same eigenvalues if and only if their trace and determinant coincide... – Henrik Schumacher Aug 3 at 5:21
• @HenrikSchumacher Thank you very much for your help. – A little mouse on the pampas Aug 3 at 6:00

Not too hard to do, if you recall that one can use a rotation matrix to perform the required orthogonal similarity transformation:

{{{a, 2}, {2, b}}, TrigExpand[RotationMatrix[2 ArcTan[u]]]} /.
Solve[With[{rot = TrigExpand[RotationMatrix[2 ArcTan[u]]]},
{{1, -2}, {-2, 4}}]]],
{a, b, u}]
{{{{1, 2}, {2, 4}}, {{-(3/5), 4/5}, {-(4/5), -(3/5)}}},
{{{4, 2}, {2, 1}}, {{0, 1}, {-1, 0}}},
{{{1, 2}, {2, 4}}, {{3/5, -(4/5)}, {4/5, 3/5}}},
{{{4, 2}, {2, 1}}, {{0, -1}, {1, 0}}}}


Note also the use of the Weierstrass substitution to ease the algebra done by Solve[].

As an example verification,

{{0, -1}, {1, 0}}.{{4, 2}, {2, 1}}.Transpose[{{0, -1}, {1, 0}}] == {{1, -2}, {-2, 4}}
True

• Thank you very much. How to extend it to the case of three-dimensional matrix? A = {{a, 0, 1}, {0, a, -1}, {1, -1, a - 1}}; Transpose[Q] . A . Q == {{1, 0, 0}, {0, 1, 0}, {0, 0, 0}} I want to find the expression of the matrix Q. – A little mouse on the pampas Aug 13 at 7:26
• That should be a separate question. – J. M.'s discontentment Aug 14 at 1:41
• You can answer this question here. I have prepared a reward for you. – A little mouse on the pampas Aug 18 at 1:00
• I have updated this question and hope you can update your answer. – A little mouse on the pampas Aug 18 at 1:14
• You have misinterpreted my recommendation; I said that you should ask a new question for the $3\times 3$ case, since that is no longer related to your original question. – J. M.'s discontentment Aug 19 at 7:22