# Eigenvectors choose intuitive ordering/sorting

Starting from some symmetric $L\times L$ matrices $M$(see below), I want to compute the eigenvectors in Mathematica, in order to construct an orthogonal operator $U$ such that

$U^T.M.U=D$

yields a diagonal matrix. Now, I'm not really satisfied with the default ordering.

For constructing the matrices, I first define, with eg. $L=5,n=1;$ the vectors

 dmcos = Array[- Cos[-Pi + 2 Pi (# - 1)/L ] &, L];
dn = ConstantArray[J, L - n];

• If the matrix is already diagonal (M0=DiagonalMatrix[dmcos]) the expected and orthogonal matrix of eigenvectors would be the identity-matrix of course(which is what I prefer), but the result of

U=N@Eigenvectors[M0]//Transpose


is a different one, although it consists only of 0's and 1's as well.

• If more diagonals have nonzero elements (M1=SparseArray[{Band[{1, 1}] -> dmcos, Band[{1, n + 1}] -> dn, Band[{n + 1, 1}] -> dn)]//Normal), I would like to have the eigenvectors sorted in the same way as M0, to be a bit more precise, if we would vary J continuously from 0 to some finite value, every single column in the matrix U should change continuously as well.

I explicitly want to construct a matrix $U$ for a different number of $J$'s because I want to transform other matrices in the same way as $M_0$ changes to $M_1$ so I need to keep track of the correspondence of the eigenvectors with rows and columns in $M$. Intuitively, the ordering I prefer is what I expected from the beginning when diagonalizing $M_1$ but it turns out not to be true, as according to the documentation eigenvectors are sorted according to the absolute value of the corresponding eigenvalues. I tried a generalized eigenvalue as well, which seemed to do slightly better(but I want to be sure I get the right results, not just think it) and a bunch of inverse transformations and so on, but the more I think about it, the more I seem to confuse myself. Nevertheless, what I want is just a simple thing, you could look at $U$ as a transformation matrix that transforms $M0$ to $M1$ and vice versa (which is the way I want it) so it would seem to me there's a short and easy way to do this?

• In general what you are asking for is not possible. For example, the eigenvectors for $\begin{bmatrix}1&\epsilon\\\epsilon&1\end{bmatrix}$ are $(1,1)^T$ and $(1,-1)^T$ for any $\epsilon>0$, so there is no way for the eigenvector matrix to approach the identity as $\epsilon\to0$. You may have to write your own eigenvalue algorithm for your specific problem.
– user484
Dec 23, 2015 at 18:50
• @Rahul I agree, but in the case where $\epsilon=0$ the eigenspace is degenerate so if chosen the eigenvectors right then the continuity is still ok? Dec 23, 2015 at 20:03
• But you said you want the eigenvectors of a diagonal matrix to form the identity matrix.
– user484
Dec 23, 2015 at 22:12
• @Rahul that's true, thanks for your answer. The main point for me was keeping track of which eigenvector corresponded to which level, but I found a way to do it now without having to start from an identity matrix Dec 28, 2015 at 18:59

eig=Eigensystem[M];