function table4_10

% orthogonal iteration

% error tolerance
tol=1e-6;

err=10*tol;

% matrix
n=10;
A=zeros(n,n);
a=3;
for i=1:n
    A(i,i)=a;
end
A(n,1)=1;  A(1,n)=1;

B=rand(n,n);
[Q,R]=qr(B);
eigens0=ones(1,n);
k=0;
while err>tol
    k=k+1;
    B=A*Q;
    [Q,R]=qr(B);
    for ic=1:n
        eigens(ic)= dot(Q(:,ic),A*Q(:,ic))/dot(Q(:,ic),Q(:,ic));
    end
    err=norm((eigens-eigens0)./eigens,inf);
    eigens0=eigens;
    fprintf('\\, %d \\, &\\,\\, %12.8f \\,\\,&\\,\\, %12.8f \\,\\,&\\,\\, %12.8f \\,\\,&\\,\\,   %12.8f \\\\\\hline \n',k,eigens(1),eigens(2),eigens(7),eigens(n))
    if err < tol
        break
    end

end








