Jutho / KrylovKit.jl

Krylov methods for linear problems, eigenvalues, singular values and matrix functions
Other
300 stars 38 forks source link

Normalization of eigenvectors for real, nonsymmetric #13

Closed amilsted closed 5 years ago

amilsted commented 5 years ago

Hi Jutho!

I'm not sure if this is a bug, but I noticed that eigsolve() does not always return normalized eigenvectors. Are the eigenvalues supposed to be normalized? I couldn't see anything about this in my cursory glance at the docs.

Anyway, I am giving eigsolve() a real, nonsymmetric sparse matrix (Julia's built-in sparse type) and the eigenvectors have norm 1 or sqrt(2). If I make the element type of the matrix complex (without changing the values), all eigenvectors have norm 1.

For more detail, I was just diagonalizing the Ising spin chain (as one does...) via T*H, where T is a translation by one site and H is the Hamiltonian. The translation-invariant states (with real eigenvalues) had norm 1, the others had norm sqrt(2).

Ash

PS: Thanks for all the cool code you're putting out at the moment. Much appreciated! 🥇

Jutho commented 5 years ago

That is certainly a bug. From your description, I assume it has to do with how I combine the real and imaginary part of the Schur vectors in the real schur decomposition. I'll take a look at this asap.

Jutho commented 5 years ago

Ok this seems to be because of how ?trevc in lapack works:

Each eigenvector is normalized so that the element of largest magnitude has magnitude 1; here the magnitude of a complex number (x,y) is taken to be |x| + |y|.

I will add an explicit normalization step

Jutho commented 5 years ago

Strange that nobody noticed/complained so far.

Jutho commented 5 years ago

Check out v0.3.2 :-)

Jutho commented 5 years ago

Or not

Jutho commented 5 years ago

I should have awaited tests; clearly I broke something.

Jutho commented 5 years ago

Unless you care very much about the info.residuals being correct, you should be fine. I forgot to update those. Will fix tonight.

Jutho commented 5 years ago

Proper fix in v0.3.3