% Script P2
clc
randn('seed',0)
rand('seed',0)
n = 1000;
d = n*rand(n,1);
v = randn(n-1,1);

itMax = 100000;
tol = 10^-3;
[lambdaMax,xMax,its] = DomArrow(d,v,tol,itMax);

A = diag(d); A(n,1:n-1) = v'; A(1:n-1,n) = v;
[Q,D] = schur(A);
[d0,idx] = sort(diag(D),'descend');
evecSine = sqrt(1 - (Q(:,idx(1))'*xMax)^2);

fprintf('true = %15.10f\n',d0(1))
fprintf('computed = %15.10f\n',lambdaMax)
fprintf('evecSine = %15.10f\n',evecSine)
fprintf('iterations = %5d\n',its)
fprintf('ratio = %15.10f\n',d0(2)/d0(1))