# Finding the transformation to get a matrix from another matrix

I have two symbolic matrices, with the same eigensystems, with arbitrary elements that read

Amat = ( {
{a11, a12, a13, a14},
{a21, a22, a23, a24},
{a31, a32, a33, a34},
{a41, a42, a43, a44}
} );
Bmat = ( {
{b11, 0, 0, 0},
{0, b22, b23, 0},
{0, b32, b33, 0},
{0, 0, 0, b44}
} );


How can I find a transformation that imposes $$U^{-1} A U =B$$? The b11 and b44 elements can be considered as two numbers proportional to the eigenvalues of Amat. However, calling Eigenvectors[Amat] does not give me a simplified solution for this $$4 \times 4$$ matrix. I am mainly concerned with symbolic calculations, but even a numerical solution is appreciated if symbolic calculations seem infeasible.

• What does "proportional to the eigenvalues" mean? An eigenvalue is a number. It is not surprisung that Eigenvectors does not work when applied to a fully symbolic matrix. Overall, I think the question is not clear. Jul 12, 2022 at 18:29
• I meant ‘\alpha \lambda’ with $\lambda$ be one of the eigenvalues of Amat. Jul 12, 2022 at 19:58
• For this to work, the eigenvalues of A must equal the eigenvalues of B. Otherwise no such U exists. If they are equal, then the matrix given by Eigenvectors will do the transformation. Jul 12, 2022 at 21:38
• @bills Bmat is not a diagonal matrix so it needs more work on eigenvalues. Jul 13, 2022 at 2:41
• @bills It is alright if both matrices have the same eigenvalues. But how can I find the transformation matrix U? Jul 13, 2022 at 5:12

I reinterpreted OPs question a little bit: Given two square matrices $$A$$ and $$B$$ of the same size, we want a function that decides if there exists an invertible matrix $$U$$ such that $$AU = UB$$. If yes, return $$U$$. If no, return {}.

Further simplifications. I am going to assume without check that A and B are diagonalizable, since I do not want to get into Jordan normal forms and such. I am going to assume that the matrices have numeric entries. I am going to check if the eigenvalues coincide without reordering them; note that Eigensystem order eigenvalues by absolute value, and if a matrix has several eigenvalues with same absolute value (for example unitary matrices) then what I do here can easily fail.

findIntertwiner[A_?SquareMatrixQ,B_?SquareMatrixQ] := Module[{vecsA,valsA,vecsB,valsB},
{valsA,vecsA} = Eigensystem[A];
{valsB,vecsB} = Eigensystem[B];
If[Chop[Norm[valsA-valsB]]===0, (* <--- will work sometimes, not always *)
Transpose[vecsA].Inverse[Transpose[vecsB]],
{}]];


Example:

SeedRandom[1];
A = RandomReal[{-1,1},{4,4}];
V = RandomReal[{-1,1},{4,4}];
B = Inverse[V].A.V;

(* find U *)
U = findIntertwiner[A,B]

(* check that this gives zero *)
Chop[Norm[A.U-U.B]]


Note that U need not coincide with V, since the intertwiner is not unique.

• @usr293787 (+1) With a bit modifying B to have the block structure in my question and considering A = Inverse[V] . DiagonalMatrix[Eigenvalues[B]] . V; Your script does the job for me. Thank you! Jul 13, 2022 at 14:59