# Reorder eigenvalues in Schur factorization in descending order

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?

Say,

H=[-149 -50 -154; 537 180 546; -27 -9 -25];
[U,T]=schur(H);
[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);

• What is "descending order" for complex eigenvalues? – 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.]

• 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. – Jake Apr 14 '20 at 1:22
• You are correct; the fix in your other answer should work. – Federico Poloni Apr 14 '20 at 7:14
• Thanks for your answer. It made things clearer. – Jake Apr 14 '20 at 7:43