clear all
A = [1, 2, 3, -2; 4, 5, 6, -5 ; 7, 8, 9, -5; 10, 11, 12, 4];
AA = [A,-A;-2*A,3*A];
[U,T] = schur(AA);
v = [6,6,5,4,4,3,2,1]; % trivial, no swap required
[US, TS] = ordschur(U,T,v);
TS
select = sortcluster(v)
US = U;
TS = T;
for i = 1:size(select,1)
  [US,TS] = ordschur(US,TS,select(i,:));
end
TS
v = [1,1,2,3,3,4,5,6]; % reverse order
[US, TS] = ordschur(U,T,v);
TS
select = sortcluster(v)
US = U;
TS = T;
for i = 1:size(select,1)
  [US,TS] = ordschur(US,TS,select(i,:));
end
TS
v = [2,2,1,3,3,6,5,4];
[US, TS] = ordschur(U,T,v);
TS
select = sortcluster(v)
US = U;
TS = T;
for i = 1:size(select,1)
  [US,TS] = ordschur(US,TS,select(i,:));
end
TS
v = [3,3,2,4,4,1,5,6];
tic
[US, TS] = ordschur(U,T,v);
toc
TS
select = sortcluster(v)
US = U;
TS = T;
for i = 1:size(select,1)
  [US,TS] = ordschur(US,TS,select(i,:));
end
TS % here I get something different, but correct
v = [5,5,4,3,3,2,1,6];
tic
[US, TS] = ordschur(U,T,v);
toc
TS
select = sortcluster(v)
US = U;
TS = T;
for i = 1:size(select,1)
  [US,TS] = ordschur(US,TS,select(i,:));
end
TS 
v = [1,2,3,4,5,6,7,8]; % this v is not correct, the result is
		       % completely different from matlab
tic
[US, TS] = ordschur(U,T,v);
toc
TS
select = sortcluster(v)
US = U;
TS = T;
for i = 1:size(select,1)
  [US,TS] = ordschur(US,TS,select(i,:));
end
TS 
