To sort the eigenvalues to be increasing in magnitude, use the following:
[U, d] = eig(k, m, 'vector');
[d, ind] = sort(d);
U = U(:, ind);
The eig function doesn't sort the eigenvalues it returns, for two reasons:
1) This is not needed for many applications, and would slow down the computation time for these cases. 2) For non-symmetric eigenvalue problems, the eigenvalues are complex, and none of the sorting methods for complex values are very satisfactory.
For symmetric problems (for the generalized case, this means both matrices are symmetric, and the second matrix is also positive definite), the eigenvalues are typically returned in ascending order by eig, but this is not a guarantee.
Best Answer