I've two matrices A
and B
, and I try to find the similarity transformation between them by the following code snippet adopted from the method described here:
In[74]:= (*Data*)
A = {{-I, 0, 0, 0}, {0, I, 0, 0}, {0, 0, 0, -I}, {0, 0, -I, 0}};
B = {{0, 1, 0, 0}, {-1, 0, 0, 0}, {0, 0, 0, I}, {0, 0, I, 0}};
(*Search for x and y based on characteristic polynomial*)
n = Length@A;
Id = IdentityMatrix@n;
solxy = SolveAlways[Det[A - l*Id] == Det[B - l*Id], l]
(*Update data*)
A = A /. solxy[[1]];
B = B /. solxy[[1]];
(*Solve for general P*)
P = Array[p, {n, n}];
solP = Solve[P . B == A . P, Flatten@P];
P = P /. solP[[1]]
(*Check*)
B == Inverse@P . A . P // Simplify
Out[78]= {{}}
During evaluation of In[74]:= Solve::svars: Equations may not give solutions for all "solve" variables.
Out[83]= {{p[1, 1], I p[1, 1],
p[1, 3], -p[1, 3]}, {p[2, 1], -I p[2, 1], p[2, 3],
p[2, 3]}, {p[3, 1], p[3, 2], p[3, 3], p[3, 4]}, {-I p[3, 2],
I p[3, 1], -p[3, 4], -p[3, 3]}}
Out[84]= True
In[88]:= P
Out[88]= {{p[1, 1], I p[1, 1],
p[1, 3], -p[1, 3]}, {p[2, 1], -I p[2, 1], p[2, 3],
p[2, 3]}, {p[3, 1], p[3, 2], p[3, 3], p[3, 4]}, {-I p[3, 2],
I p[3, 1], -p[3, 4], -p[3, 3]}}
As you can see, it gives a general form symbol matrix P
as the result, and with all the symbols setting to 1, the following form will be obtained:
In[95]:= P /. {p[1, 1] -> 1, p[1, 3] -> 1, p[2, 1] -> 1, p[2, 3] -> 1,
p[3, 1] -> 1, p[3, 2] -> 1, p[3, 3] -> 1, p[3, 4] -> 1}
Out[95]= {{1, I, 1, -1}, {1, -I, 1, 1}, {1, 1, 1, 1}, {-I, I, -1, -1}}
But this method is a little complicated and not intuitive. Any enhancements/suggestions/comments about this method will be highly appreciated. I also attached the code snippet shown above.
Regards, HZ
Attachments: