function table4_2

% power method

% number of iterations
K=9;

% matrix
n=2;
A=zeros(n,n);
A(1,1)=2;  A(1,2)=1;  A(2,1)=1; A(2,2)=2;
evalue=3;

% start off guess
%y=rand(n,1);
y=[2; 0];
%y(1)=-3; y(2)=2;

k=0;
vv=100;
z=A*y;
v=dot(y,z)/dot(y,y);
err=abs(v-evalue);
errv=100;
fprintf('%d & %15.12f & %5.2e   \n',k,v,err/errv)

% power method
dv=1;
dvv=1;
for k=1:K
    vv=v;
    dvv=dv;
    errv=err;
    y=z/norm(z,2);
    z=A*y;
    v=dot(y,z);
    dv=v-vv;
    err=abs(v-evalue);
    fprintf('%d & %15.12f & %5.2e  & %5.2e \n',k,v,err/errv,dv/dvv)
end

% y
% z