function [Q,T] = Swap3(T0)
% T0 is a 3-by-3 matrix with the property that T0(2:3,1) = 0 and T0(2:3,2:3)
% has complex eigenvalues.
% Q is orthogonal with the property that Q'*T0*Q = T and T(3,1:2) = 0.

% Suppose y is a nonzero vector so y'*T0 = t11*y'
% If Q is orthogonal and Q'y = alpha*e3, then
% (Q*e3)'T0 = t11(Q*e3)'
% i.e.,
% e3'*(Q'*T0*Q) = t11*e3'
% so
% x x x
% Q'*T0*Q = x x x
% 0 0 t11

% Compute y...
%
% t11 0 0 y1 y1
% t12 t22 t32 y2 = t11 y2
% t13 t23 t33 y3 y3
%
% Since y1 can be any nonzero, set y1 = -1 for then
%
% t22-t11 t32 y2 = t12
% t13 t33-t11 y3 t13
%
M = [T0(2,2)-T0(1,1) T0(3,2) ;...
T0(2,3) T0(3,3)-T0(1,1)];
y = [-1; M\[T0(1,2);T0(1,3)]];

% Compute Q.
% If Q'*y = alpha*e1 and
% 0 0 1
% E = 0 1 0
% 1 0 0
% then
% (QE)'y = alpha(E*e1) = alpha*e3
%
% (I - 2vv')y = alpha*e1 ...
[v,alpha] = house(y);
% ((I - 2vv')E)'y = alpha*e3

Q = eye(3,3) - 2*v*v';
Q = Q(:,3:-1:1);
T = Q'*T0*Q;