MATLAB: How to seperate complex numbers based on imaginary values.

complex numberseigen values

Hi, I am using eig(A) to find eigen values of a 8×8 matrix. There are 8 eigen values for the matrix. But only four of them are complex numbers while the other four are pure real numbers. I need only the values with imaginary parts for my further computations. How do I seperate them? Thanks.

Best Answer

K = rand(8) ;
E = eig(K) ;
E = E(imag(E) ~= 0);
Note, though, that eigenvalues should be entirely real can end up with a small imaginary component due to round-off error. You might want to use something like
tolerance = 1e-10;
E = E( abs(imag(E)) <= tolerance );
Related Question