How to keep track of order eigenvalue in eig or eigs?

146 views (last 30 days)
Luqman Saleem on 13 Apr 2020
Commented: Francesco Troisi on 29 Apr 2022 at 10:24
I have a matrix equation defined at each point of variable k. The equation is where
and is a 6-by-6 matrix.
Once I solve my matrix and I plot the eigenvalues using eig (and eigs) results, I get the following:
But the correct results are 3 two-fold lines of the following form (here the x-axis is little shifted and in some other units, but essentially it is same as my x-axis).
I am trying to figure out what I am doing wrong. My solution looks someone close to the correct solution but that mess in between the lines is annoying.
May be the the order in which eig() (or eigs()) function return eigenvalues is my problem. I am have used both eig(M_k) and eigs(M_k) function. They both give almost identical results.

Ameer Hamza on 13 Apr 2020
The order of eigenvalues and eigenvectors is an issue with the MATLAB's eig() function. John's submission on FEX provides a workaround: https://www.mathworks.com/matlabcentral/fileexchange/22885-eigenshuffle
Ameer Hamza on 14 Apr 2020

Christine Tobler on 13 Apr 2020
The eigenvalues returned by EIG are not sorted in any particular order generally (for some special types of matrices (e.g. exactly symmetric), they might often be sorted in the same order, but we make no guarantees that this is always the case). For EIGS the eigenvalues are sorted in the order given by option sigma (e.g. 'largestabs', ...).
To sort the eigenvalues returned, just call sort after computing EIG:
d = eig(A);
d = sort(A);
or, for eigenvectors too,
[U, D] = eig(A);
[~, ind] = sort(diag(D));
D = D(ind, ind);
U = U(:, ind);
Since you are computing EIG of multiple matrices, if the lines describing each eigenvalue in your plot cross, this will not show continuous lines. It's not possible for each individual computation of eigenvalues to know about the connection to another, very similar, matrix A and its eigenvalues. In this case, the File Exchange package eigenshuffle that Ameer recommends may help you.

Hongwei Guo on 17 Apr 2022
After a long time struggling, I think I found a better way to sort the eigen values to the original order. First, I've tried eigenshuffle function, it does not work well, at least for my case. BTW, I am solving a eigen value problem of a Hamiltonian. Matlab's ordering can not provide correct band structure.
Here's my method: eigen value perturbation method. For a matrix A having lambda1,...lambdaN as eigen values, A+E must have the eigen values of lambda1+eps1,..., lambdaN+epsN, where perturbation matrix E = diag([eps1,...,epsN]). If we control the value of eps_i to be different, we actually can add a different marker to the original eigen value, this marker can be simply ascending values or just random. Later we can sort the eigen values of by the perturbation eps_i. I'm not going to post code here, if you guys have questions, you can ask here. Thanks!
Francesco Troisi on 29 Apr 2022 at 10:24
Dear Hongwei Guo,
I am also working with the eigenvalue problem of an Hamiltonian and I have the same issue. I am interested in your algorithm, it seems very elegant. Could you please provide further information? How do you reconstruct the original position of the eigenvalues?
Best Regards,
Francesco Troisi

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by