In this command:

[US,TS] = ordschur(U,T,select)

what should replace the select to rearrange the eigenvalues in descending order (maximum value starts at the upper leftmost cell) as per ordschur Matlab documentation?


H=[-149 -50 -154; 537 180 546; -27 -9 -25];
[US,TS]=ordschur(U, T, select);

An error will come after the last line. I've tried the different available keywords but none of them was able to rearrange the eigenvalues in descending order such that the diag(TS) = [3 2 1].

Please consider also when:

H = magic(6);
  • 2
    $\begingroup$ What is "descending order" for complex eigenvalues? $\endgroup$ – Federico Poloni Apr 13 '20 at 14:06

I understand it now. select must be a vector. So it can be renamed. Here's a little change to ensure that the eigenvalues are in descending order.

H = magic(6);
[U, T] = schur(H);
[~, p] = sort(diag(T));
[~, r] = sort(p);
[US, TS] = ordschur(U, T, r);

I replaced select with r and it works fine.


In your example, [US,TS]=ordschur(U, T, [1 2 3]); will work.

The documentation is quite cryptic.

Given a vector CLUSTERS of cluster indices, commensurate with E = EIG(T), and such that all eigenvalues with the same CLUSTERS value form one cluster, [US,TS] = ordschur(U,T,CLUSTERS) will sort the specified clusters in descending order along the diagonal of TS, the cluster with highest index appearing in the upper left corner.

Did you understand that? Neither did I, at first. :) Essentially select can be a vector of indices: select(i) tells you in which cluster the ith eigenvalue needs to go. These clusters are sorted in decreasing order: if e.g. select = [1 2 3 3 2 1], then the 3rd and 4th eigenvalue (in the order specified by the diagonal of T) will come first (in an unspecified order), then the 2nd and 5th (in an unspecified order), then the 1st and last (in an unspecified order).

To sort the eigenvalues in decreasing order, you can use the fact that the second output of sort is a vector of indices that specifies a permutation.

[U, T] = schur(H);
[~, select] = sort(ordeig(T));
[US, TS] = ordschur(U, T, select);

(the second output of sort is a vector of indices that we can use for this purpose. sort sorts increasingly by default, but then ordschur sorts cluster numbers in descending order, so it magically works.)

[EDIT: this still does not work on all matrices; see @Jake's answer below for a corrected version.]

  • 1
    $\begingroup$ Your code: [~, select] = sort(ordeig(T)); [US, TS] = ordschur(U, T, select); works perfectly for the given matrix H. But when I applied it on H = magic(6) and other 16x16 matrix, it was unable to sort the eigenvalues in descending order. $\endgroup$ – Jake Apr 14 '20 at 1:22
  • $\begingroup$ You are correct; the fix in your other answer should work. $\endgroup$ – Federico Poloni Apr 14 '20 at 7:14
  • $\begingroup$ Thanks for your answer. It made things clearer. $\endgroup$ – Jake Apr 14 '20 at 7:43

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.