% P2

% Set up a 20-by-20 matrix with eigenvalues
%      -1 + i  , -1 -i     (repeated 2 times)
%      -2 + 10i, -2 - 10i  (repeated 6 times)
%      -.01, -1, -1.5, -2

randn('seed',0)
n = 20;
A = triu(randn(n,n));
M1 = [-1  2; -2 -1];         % eigenvalues = -1 +- i
M2 = [-2  .1;  -1000 -2];    % eigenvalues = -2 +- 10i
A(1:2,1:2)   = M2; A(3:4,3:4)     = M1; A(5:6,5:6)     = M2; A(7:8,7:8)     = M2;
A(9:10,9:10) = M2; A(11:12,11:12) = M1; A(13:14,13:14) = M2; A(15:16,15:16) = M2;
A(17,17) = -.01; A(18,18) = -1; A(19,19) = -1.5; A(20,20) = -2;

% A is block upper triangular with the presecribed eigenvalues.
% Now scramble it up with a random orthogonal similarity transformation

[Q,R] = qr(randn(n,n));
A = Q'*A*Q;

Near2Instab(A)
shg