function table4_7

% rayleigh quotient iteration

% number of iterations
K=4;

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

% exact value
evalue=1+a;

% start-off values
k=0;
err=1;
y=rand(n,1);
y=y/dot(y,y);
z=A*y;
v=dot(y,z);

fprintf('\n k  \t   v_k \t\t\t  Error \n')
fprintf('%d \t %15.12f    \n',k,v)
%fprintf('%d & %15.12f & %5.2e   \n',k,v,err)

for k=1:K
    vv=v;
    B=A-v*eye(n);
    z=B\y;
    y=z/norm(z,2);
    v=dot(y,A*y);
    err=abs(v-3);
    vv=v;
    fprintf('%d \t %15.12f \t %5.2e   \n',k,v,err)
    %fprintf('%d & %15.12f & %5.2e  \n',k,v,err)
    if err==0
        break
    end
end

