function P1
% Checks BigEvec

randn('seed',0)
clc
% Simple example...
n = 10; alpha = .1; tol = .000001;
U = GenOrth(alpha,n);
[v,its] = BigEvec(U,alpha,tol)
 
% How things change with respect to alpha and tol...
fprintf('\n\n\n\n alpha      tol        Residual       its\n')
disp('---------------------------------------------------------')
for alpha = [.5 .1 .05 .01]
    for tol = [.001 .0001 .00001 ]
        U = GenOrth(alpha,n);
        [v,its] = BigEvec(U,alpha,tol);
        fprintf(' %5.3f   %10.3e   %10.3e  %8d\n',alpha,tol,norm(U*v-v),its)
    end
end



function U = GenOrth(alpha,n)
% Generates an n-by-n alpha-orthogonal matrix
D = zeros(n,n);
m = floor((n-1)/2);
% Where we will put all but the eigenvalue 1...
theta = linspace(alpha,pi,m);
% Build a block diagonal alpha-orthogonal matrix...
D(1,1) = 1;
for k=1:m
    c = cos(theta(k)); s = sin(theta(k));
    D(2*k:2*k+1,2*k:2*k+1) = [c s;-s c];
end
if 2*m==n-2
    D(n,n) = -1;
end
% Now make it full via a randomn orthogonal similarity...
[Q,R] = qr(randn(n,n));
U = Q*D*Q';
