MATLAB: How to keep track of order eigenvalue in eig or eigs

algorithmeigeigenvalueeigshomeworkMATLAB

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.

Best Answer

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
Related Question