function P2Grade()

n = 3;
clc
fprintf('Example 1\n\n')
A = randn(n,n);
A = A-A';
Q = RealSchur3(A);
fprintf('|| Q''*Q - I || = %10.3e\n',norm(Q'*Q-eye(3,3)))
D = Q'*A*Q

fprintf('Example 2\n')
A = [ 0 0 3;0 0 4; -3 -4 0]
Q = RealSchur3(A);
fprintf('|| Q''*Q - I || = %10.3e\n',norm(Q'*Q-eye(3,3)))
D = Q'*A*Q

fprintf('Example 3\n')
A = [ 0 3 0;-3 0 4; 0 -4 0]
Q = RealSchur3(A);
fprintf('|| Q''*Q - I || = %10.3e\n',norm(Q'*Q-eye(3,3)))
D = Q'*A*Q

fprintf('Example 4\n')
A = [ 0 3 4;-3 0 0; -4 0 0]
Q = RealSchur3(A);
fprintf('|| Q''*Q - I || = %10.3e\n',norm(Q'*Q-eye(3,3)))
D = Q'*A*Q

fprintf('Example 5\n')
A = [ 0 0 0; 0 0 0; 0 0 0]
Q = RealSchur3(A);
fprintf('|| Q''*Q - I || = %10.3e\n',norm(Q'*Q-eye(3,3)))
D = Q'*A*Q

   function Q = RealSchur3CVL(A)
 % A is a 3x3 real skew-symmetric matrix.
 % Q is a 3x3 orthogonal matrix so that Q'*A*Q has the form
 %                   Q'*A*Q = [ 0  mu  0 ; -mu 0 0 ; 0 0 0]
 
 x = A(1,2); y = A(1,3); z = A(2,3);
 % Note that
 %              [ 0  x  y ] [  z ]   [ 0 ]
 %              [-x  0  z ] [ -y ] = [ 0 ]
 %              [-y -z  0 ] [  x ]   [ 0 ]
 
 [v,beta] = House([z;-y;x]);
 v = v/norm(v);
 Q = eye(3,3) - 2*v*v';
 
 % Since Qtilde*u = [*;0;0] it follows that the
 % first column of Q is a null vector for A. Thus
 % the first column of Q'*A*Q is all zeros. Since this matrix
 % is skew symmetric we must have the form
 %
 %                  [ 0  0   0 ]
 %      Q'*A*Q   =  [ 0  0  mu ]
 %                  [ 0 -mu  0 ]
 Q = Q(:,[ 2 3 1]);
 % Now we have
 %                  [ 0  mu   0 ]
 %      Q'*A*Q   =  [-mu  0   0 ]
 %                  [ 0   0   0 ]
 
