0
$\begingroup$

I need to solve the following matrix equation to find a set of solutions for matrices A and Q which satisfy the conditions.

Q = Array[x, {3, 3}]; 
A = {{a, 0, 1}, {0, a, -1}, {1, -1, a - 1}}; 
sol = FindInstance[
  Transpose[Q] . A . Q == {{b, 0, 0}, {0, c, 0}, {0, 0, 0}} && 
       Transpose[Q] . Q == IdentityMatrix[3] && b > 0 && c > 0, 
     {a, b, c, x[1, 1], x[1, 2], x[1, 3], x[2, 1], x[2, 2], x[2, 3], 
   x[3, 1], 
       x[3, 2], x[3, 3]}]

However, the above code takes about 300 seconds to output a set of solutions that meet the requirements. How can I improve this code to get a set of solutions that meet the requirements quickly?

A set of solutions satisfying conditions:

A={{2, 0, 1}, {0, 2, -1}, {1, -1, 1}};
Q={{-(1/Sqrt[2]), -(1/Sqrt[3]), 1/Sqrt[6]}, 
    {-(1/Sqrt[2]), 1/Sqrt[3], -(1/Sqrt[6])}, 
    {0, -(1/Sqrt[3]), -Sqrt[2/3]}};

Updated content & Additional questions:

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. How can I quickly get a set of solutions that meet the requirements?

$\endgroup$
6
  • 2
    $\begingroup$ Once again, you should put more effort in understanding the answer you obtained. $\endgroup$
    – xzczd
    Aug 13, 2020 at 9:33
  • $\begingroup$ @xzczd Thank you for your guidance, the code in that post is a little bit faster:(it took 115 seconds): Q = EulerMatrix[{a, b, c}]; A = {{f, 0, 1}, {0, f, -1}, {1, -1, f - 1}}; sol = FullSimplify[FindInstance[Transpose[Q] . A . Q == {{d, 0, 0}, {0, e, 0}, {0, 0, 0}} && 0 <= a <= 2*Pi && 0 <= b <= 2*Pi && 0 <= c <= 2*Pi && d > 0 && e > 0, {a, b, c, d, e, f}]] $\endgroup$ Aug 13, 2020 at 9:54
  • 2
    $\begingroup$ Select[Solve[eqn,Flatten@{Q,a,b,c}],b>0&&c>0/.#&] $\endgroup$
    – chyanog
    Aug 13, 2020 at 10:17
  • $\begingroup$ @chyanog Thank you very much for your code. $\endgroup$ Aug 14, 2020 at 2:40
  • $\begingroup$ @chyanog I have updated the question, can you quickly solve my additional new problem? $\endgroup$ Aug 18, 2020 at 1:09

1 Answer 1

8
+50
$\begingroup$

Your problem seems to be more related to finding the eigensystem of A than equation solving. For all a your matrix is symmetric and real, so using the spectral theorem you know you can diagonalize it using an orthonormal matrix Q (which seems to be exactly the problem in your question).

Using EigenSystem on A we get

Eigensystem[A]
{{-2 + a, a, 1 + a}, {{-1, 1, 2}, {1, 1, 0}, {1, -1, 1}}}

The variable a is therefore only allowed to take values $-1$, $0$, or $2$, since in your problem you specify that you need one of the eigenvalues to be zero. This corresponds to the {a,b,c} triples {-1,-1,-3}, {0,1,2} and {2,2,3}. Of course you can exchange b and c by flipping rows in Q.

The orthonormal eigenvectors, which will span Q, are generic for all a, and can be determined from EigenSystem:

Q = #/(Sqrt@Diagonal[#.Transpose[#]]) & @ Eigensystem[A][[2]]
{{-(1/Sqrt[6]), 1/Sqrt[6], Sqrt[2/3]}, 
 {1/Sqrt[2], 1/Sqrt[2], 0}, 
 {1/Sqrt[3], -(1/Sqrt[3]), 1/Sqrt[3]}}

So, for a=-1, you have the pair

A = {{-1, 0, 1}, {0, -1, -1}, {1, -1, -2}};
Q = {{-(1/Sqrt[6]), 1/Sqrt[6], Sqrt[2/3]}, 
     {1/Sqrt[2], 1/Sqrt[2], 0}, 
     {1/Sqrt[3], -(1/Sqrt[3]), 1/Sqrt[3]}}

Transpose[Q].DiagonalMatrix[{-3, -1, 0}].Q == A

for a=0

A = {{0, 0, 1}, {0, 0, -1}, {1, -1, -1}}
Q = {{-(1/Sqrt[6]), 1/Sqrt[6], Sqrt[2/3]}, 
     {1/Sqrt[3], -(1/Sqrt[3]), 1/Sqrt[3]}, 
     {1/Sqrt[2], 1/Sqrt[2], 0}}

 Transpose[Q].DiagonalMatrix[{-2, 1, 0}].Q == A

and for a = 2

A = {{2, 0, 1}, {0, 2, -1}, {1, -1, 1}}
Q = {{1/Sqrt[3], -(1/Sqrt[3]), 1/Sqrt[3]}, 
     {1/Sqrt[2], 1/Sqrt[2], 0}, 
     {-(1/Sqrt[6]), 1/Sqrt[6], Sqrt[2/3]}}

Transpose[Q].DiagonalMatrix[{3, 2, 0}].Q == A

Edit for updated question

To solve the system in your update, you can again use Eigensystem

A = {{1 - a, 1 + a, 0}, {1 + a, 1 - a, 0}, {0, 0, 2}} /. a -> 2;
Eigensystem[A]
{{-4, 2, 2}, {{-1, 1, 0}, {0, 0, 1}, {1, 1, 0}}}
Q = Normalize /@ {{-1, 1, 0}, {0, 0, 1}, {1, 1, 0}};

Transpose[Q].DiagonalMatrix[{-4, 2, 2}].Q == A
True

or

Q.A.Transpose[Q]
{{-4, 0, 0}, {0, 2, 0}, {0, 0, 2}}
$\endgroup$
8
  • $\begingroup$ Your method is not valid for the following code: A = {{1, 2, -3}, {-1, 4, -3}, {1, -2, 5}}; Eigensystem[A]; Q = Normalize /@ (Eigensystem[A][[2]]); Transpose[Q].DiagonalMatrix[{6, 2, 2}].Q == A. $\endgroup$ Aug 19, 2020 at 8:28
  • $\begingroup$ Your other examples worked, since they were symmetric matrices, for which the spectral theorem guarantees that a decomposition $Q^TAQ=D$ exists. The matrix in your comment is not symmetric, so it is not even guaranteed to be diagonalizable, but generally it would have the form $P^{-1}AP=D$. Intuitively I would say that it is not possible to find a $Q$ such that $Q^TAQ=D$ provided that $P^{-1}AP=D$ (with $Q\ne P$ and $P$ not orthonormal), since there are uniqueness statements about similarity transformations to the diagonal matrix of eigenvalues, but perhaps I am missing a subtle point. $\endgroup$
    – Hausdorff
    Aug 19, 2020 at 14:54
  • $\begingroup$ Also, for your example in the comment, FindInstance also finds no solution: FindInstance[Thread[Transpose[Q].A.Q == DiagonalMatrix@Eigenvalues[A]], Flatten[Q], Reals] yields {} $\endgroup$
    – Hausdorff
    Aug 19, 2020 at 14:56
  • $\begingroup$ DiagonalizableMatrixQ[A]==True $\endgroup$ Aug 19, 2020 at 22:32
  • 1
    $\begingroup$ Yes, but your matrix is not symmetric, so Transpose is not sufficient. For arbitrary (diagonalizable) matrices A you can use Q = Transpose[Normalize /@ (Eigensystem[A][[2]])]; Q.DiagonalMatrix[Eigenvalues@A].Inverse[Q] == A. If A is symmetric, you can replace Inverse with Transpose, since then Inverse[Q] === Transpose[Q], as Q is orthonormal. $\endgroup$
    – Hausdorff
    Aug 19, 2020 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.