I have two matrixes with values differs only slightly


Hls1 - Hls2 // Flatten // Abs // Max
(* 5.46584*10^-10 *)

but EigenSystem gives large difference.

Eigensystem[Hls1] - Eigensystem[Hls2] // Flatten // Abs // Max
(* 1.99918 *)

While Matlab seems to give reasonable close results (MATLink package by Szabolcs is here).


MSet["Hls1", Hls1]
MSet["Hls2", Hls2]

MEvaluate["[V1,D1] = eig(Hls1)"];
MEvaluate["[V2,D2] = eig(Hls2)"];

(* ">> 
ans =


" *)

(* ">> 
ans =


" *)

It appears that both values of the eigensystem for the two matrixes are correct, but there is a phase jump in the eigenvectors. So why is there this phase jump? Does Mathematica use two different methods on the two matrixes?

Note that we can always manually correct the phase by setting a convention, but sometimes this is tedious and time consuming, if one only requires the consistence of the phase.

  • $\begingroup$ You might try sorting the eigenvectors by length, then taking their absolute values (lengths) before comparison. That way, differences in signs (which are sensitive to both data variations and algorithms) will be ignored. $\endgroup$ – David G. Stork Feb 24 '15 at 17:09

You are apparently looking for a way to reliably compare two numerical matrices by using their eigensystems. This can always be done for normal matrices by using the eigenvectors to construct their spectral decomposition. To do that, you shape the eigenvectors into the equivalent system of projectors. Then you can compare the projectors instead. The good thing about projectors is that they don't even contain the irrelevant phase factor you're worried about in the first place:

{eval1, evec1} = Eigensystem[Hls1];
{eval2, evec2} = Eigensystem[Hls2];

esProject1 = {eval1, Map[TensorProduct[Conjugate[#], #] &, evec1]};
esProject2 = {eval2, Map[TensorProduct[Conjugate[#], #] &, evec2]};

esProject1 - esProject2 // Flatten // Abs // Max

(* ==> 6.40185*10^-6 *)

The vectors returned by Eigensystem are turned into matrices by using TensorProduct. This is where the phase gets annihilated, and the result is a projector onto the subspace of that eigenvalue. To see that the spectral representation in this case indeed reproduces the original matrix, you would do something like this:

(Total[Times @@ esProject1] - Hls1) // Flatten // Abs // Max

(* ==> 3.44264*10^-7 *)

This approach works with your matrices because they are both Hermitian. I am assuming this is OK because you didn't say otherwise... Also, the normalization of the eigenvectors that I assume here is only true if the matrices are numerical.

Of course you can also use the construction I wrote in the last line directly to compare the matrices: i.e., reconstruct the matrices using Total[Times @@ esProject1] and then compare the results. That's probably the best way if you have degeneracies.

| improve this answer | |
  • $\begingroup$ Thanks for the answer, indeed a Hermit matrix can always be decomposed into its spectrum form $H=\sum_n \lambda_n \left|n\right\rangle \left\langle n \right|$, and comparing the spectrum is a good way to compare the original matrix. But I am actually interested in calculating the eigenvectors of a parametric matrix which changes slightly in a range and found that this behavior of Eigensystem. I'm wondering what costs this seems random behavior? Does Eigensystem use LAPACK under the hood? $\endgroup$ – xslittlegrass Feb 24 '15 at 19:47
  • $\begingroup$ That's probably one of the mysteries that only a Wolfram employee can answer definitively... it's worth knowing that such discrepancies exist, but since there is no reason to not expect them, I would simply not depend on any properties of the eigenvectors that are mathematically not required to have any specific value. $\endgroup$ – Jens Feb 24 '15 at 20:32
  • $\begingroup$ Congrats on 50K :-) $\endgroup$ – Mr.Wizard Feb 26 '15 at 0:31
  • $\begingroup$ @Mr.Wizard Thanks - the view must be nice up there where you are at 130K... maybe I'll find out one day. $\endgroup$ – Jens Feb 26 '15 at 1:49
  • 1
    $\begingroup$ @xslittlegrass, yes, LAPACK is used under the hood. Look at the result of ??LinearAlgebra`LAPACK`*, for instance. $\endgroup$ – J. M.'s technical difficulties Jul 9 '15 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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