# Finding a unitary matrix in Mathematica

I have the following equation : $\tilde{B} = U B U^{\dagger}$

I also know both $B$ and $\tilde{B}$ , I just want to find the matrix U, that gives me the transformation. I tried using LinearSolve, but I can't get it into the form required by that function. Is there another way to do that?

I must note that the condition that U be Unitary is ESSENTIAL. I make this remark because of the interesting solutions proposed below, none of which, however, gives a unitary matrix U.

Edit: If it is of any help, the two matrices B and $\tilde B$ are two quantum density matrices.

Edit2: I also added the two matrices here: http://pastebin.com/s3B1T0HD

• If $\mathbf B$ is normal and similar to $\tilde{\mathbf B}$, then it's actually quite easy... Nov 3 '15 at 11:17
• How big are these matrices? Nov 4 '15 at 12:12
• smallest is 16x16. the largest case I want to test is 64x64. Nov 4 '15 at 12:14
• Okay, let me give you something to try on your smallest case: apply Chop[SchurDecomposition[mat, RealBlockDiagonalForm -> False]] to both of your matrices, and check if the triangular (diagonal?) matrices produced are the same (up to roundoff and permutation). We can proceed after you do this. Nov 4 '15 at 12:19
• This gives me a matrix of vectors, every element is a column vector. The two matrices are also very different (no 2 elements are equal). Nov 4 '15 at 12:23

For normal matrices:

Find the unitary matrices $P$ and $S$ that diagonalize $\tilde{B}$ and $B$.

$D=P^{-1}\tilde{B}P\\ D'=S^{-1}BS\\ \tilde{B}=PS^{-1}BSP^{-1}\\ => U=PS^{-1}$

B1 = {{2, 1}, {-1, -1}};
B2 = {{-2, 5}, {-1, 3}};

P = Transpose@Eigenvectors@B1;
S = Transpose@Eigenvectors@B2;
U = P.Inverse@S;

B1 == Simplify[U.B2.Inverse@U]


True

• Alternatively, one could use SchurDecomposition[] to generate the required unitary matrices. Though, this solution assumes $\mathbf B$ and $\tilde{\mathbf B}$ are similar, of course. Nov 3 '15 at 11:28
• @paw: The procedure is not valid in general because B and B~ might be such that they cannot be diagonalized. Example $B$ = {{0,1},{0,0}}, $\tilde{B}$ = {{0,0},{-1,0}} and U = {{0,1},{-1,0}} Nov 4 '15 at 6:30
• @paw: the OP asks for a unitary matrix U. Your U is not unitary. Also in the final comparision you should use $U^{\dagger}$ rather than $U^{-1}$, i.e. you missed a transposition. Hence I would reject your answer. Nov 4 '15 at 6:45
• @ J.M. Despite of my comments I see another upvoting and the acceptance of the answer, without further discussion. Can somebody please explain this to me? Nov 4 '15 at 8:36
• Now I have tried the above, it does NOT give me a unitary matrix U. Does anyone have any other suggestion? I have to say that IT IS ESSENTIAL THAT U BE A UNITARY MATRIX. Nov 4 '15 at 10:57

The eigenvectors space of a normal matrix are orthogonal. So in this case you can use Orthogonalize to get a set of orthogonal eigenvectors.

H = {{1, 1 + I}, {1 - I, 1}};
{Lambda, SA} = Eigensystem[H]
UA = Orthogonalize[SA]
UAT = Transpose[UA];
DiagonalMatrix[Lambda] == ConjugateTranspose[UAT].H.UAT