  function [v,lambda] = OrthogEvec(U,tol,phi)
% U is an n-by-n orthogonal matrix with a unique eigenvalue at 1.

% tol a positive real number > the unit roundoff.

% 0 <= phi < 2pi

% lambda is the closest eigenvalue to exp(i*phi), assumed to be unique

% v is a unit 2-norm n-vector that satisfies norm(Uv-lambda*v,2)<=tol
%    and is computed via the power method.

% its is the number of required iterations
[n,n] = size(U);
v = randn(n,1); v = v/norm(v);
Uvprod = U*v; k=0
lambda = v'*Uvprod;

% Let's assume that exp(i*phi) is a unique eigenvalue. This
% means that 1 is a unique eigenvalue of exp(-i*phi)*U. If we
% apply what we learn from P1, apply power method to A = exp(-i*phi)U + I,
% This is esseniall the same as applying power method with 
% A = U + exp(i*phi)I ...

k = 0;
while (norm(Uvprod - lambda*v)>tol & k <= 1000)
    z = Uvprod + exp(sqrt(-1)*phi)*v;     % z = (U + exp(i*phi)*I)*v
    v = z/norm(z);
    Uvprod = U*v; 
    lambda = v'*Uvprod;
    k=k+1;
end


