function table4_5

% inverse iteration

% number of iterations
K=10;

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

% exact value
evalue=1+a;

% try different shifts
for icase=1:2
    if icase==1
        mu=4.8;
    else
        mu=4.4;
    end
    B=A-mu*eye(n);
    evalueB=1/(1+a-mu);
    y=rand(n,1);
    z=B\y;
    v=dot(y,z)/dot(y,y);
    eig(icase,1)=mu+1/v;
    err=abs(evalue-eig(icase,1));
    for k=1:K
        vv=v;
        y=z/norm(z,2);
        z=B\y;
        v=dot(y,z);
        eig(icase,k+1)=mu+1/v;
        eig_err(icase,k+1)=abs(eig(icase,k+1)-evalue); 
        v0=v;
    end
end

fprintf('\n k  \t   lambda_1 \t\t  Error   \t   lambda_1 \t\t  Error \n')
for kk=1:K+1
    fprintf(' %d \t %15.12f  \t %5.2e    \t %15.12f  \t %5.2e  \n',kk-1,eig(1,kk),eig_err(1,kk),eig(2,kk),eig_err(2,kk))
    %fprintf('%d \\,\\, & \\,\\, %15.12f \\,\\, & \\,\\, %5.2e  \\,\\, & \\,\\, %15.12f \\,\\, & \\,\\, %5.2e \\\\ \\hline \n',kk-1,eig(1,kk),eig_err(1,kk),eig(2,kk),eig_err(2,kk))
end









