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


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


    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?

  • 2
    $\begingroup$ 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. $\endgroup$
    – user484
    Dec 23, 2015 at 18:50
  • $\begingroup$ @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? $\endgroup$
    – Wouter
    Dec 23, 2015 at 20:03
  • $\begingroup$ But you said you want the eigenvectors of a diagonal matrix to form the identity matrix. $\endgroup$
    – user484
    Dec 23, 2015 at 22:12
  • $\begingroup$ @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 $\endgroup$
    – Wouter
    Dec 28, 2015 at 18:59

1 Answer 1


As @Rahul pointed out in the comments, it is impossible to start from the unit matrix and change J such that the eigenvectors change continuously. However, I found a nice way to keep track of the correspondence of the eigenvectors when changing J, making use of the fact that values of eigenvalues don't cross as a function of J and in Eigensystem the eigenvalues and eigenvectors are in the same order. What I'm doing is relabeling all levels such that the one with lowes dmcos comes first

U=Permute[eig[[2]],perm] //Transpose; U=Permute[U,perm2];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.