0

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?

1 Answers1

8

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}}
Hausdorff
  • 3,505
  • 1
  • 9
  • 25
  • 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`.

    – A little mouse on the pampas Aug 19 '20 at 08:28
  • 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. – Hausdorff Aug 19 '20 at 14:54
  • 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 {} – Hausdorff Aug 19 '20 at 14:56
  • DiagonalizableMatrixQ[A]==True – A little mouse on the pampas Aug 19 '20 at 22:32
  • 1
    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. – Hausdorff Aug 19 '20 at 23:01
  • So how can I get an invertible matrix Qsuch that $Q^{-1} A Q=\Lambda$? – A little mouse on the pampas Aug 19 '20 at 23:07
  • The required Q is exactly that computed by the code in my previous comment. You can see that by multiplying your equation with Q from the left, and with Inverse[Q] from the right. – Hausdorff Aug 19 '20 at 23:10
  • Thank you very much. I can diagonalize this way: Inverse[Q\[Transpose]].A.Q\[Transpose]. – A little mouse on the pampas Aug 19 '20 at 23:30