How to sort generalized eigenvalues with ordqz by absolute value in ascending or descending order?

1 view (last 30 days)
Benjamin Brennan on 21 Oct 2016
Edited: Benjamin Brennan on 21 Oct 2016
I have a problem that I need to sort the generalized eigenvalues on the (quasi) triangular matrices from a QZ decomposition in ascending order by magnitude some times and descending order by magnitude other times.
None of the canned orderings from ordqz fit this need, so I have been attempting to do this in the following way:
amat=20*rand(6,6);
bmat=20*rand(6,6);
[aamat, bbmat, q,z]=qz(amat,bmat);
E=abs(ordeig(aamat,bbmat));
[~,clus]=sort(E,'ascend');
aaamat=aamat;
bbbmat=bbmat;
qq=q;
zz=z;
for i=6:1
select=clus==i
[aaamat,bbbmat,qq,zz]=ordqz(aaamat, bbbmat,qq,zz,select);\
E=abs(ordeig(aaamat,bbbmat));
[~,clus]=sort(E,'ascend');
end
The above is intended to sort the diagonal from smallest to largest. This never seems to achieve what I'm looking for however. On top of that as i've inspected the clus vector that sort spits out many times that vector has the wrong ordering even though the vector of sorted values is correct.
How do I make this work?