load west0479;
A = west0479;
shift = 15 + 35i;

t1=cputime;
[L,U,P] = lu(A - shift*speye(479));
q = ones(479,1);
for j = 1:10 
      q = P*q;
      q = L\q;
      q = U\q;
      [bgst,index]=max(abs(q));
      sigma(j+1) = q(index(1));
      q = q/sigma(j+1);
    end
t2 = cputime;
t2 - t1

t1=cputime;
q = ones(479,1);
B = A - shift*speye(479);
for j = 1:10 
      q = B \ q;
      [bgst,index]=max(abs(q));
      sigma(j+1) = q(index(1));
      q = q/sigma(j+1);
    end
t2 = cputime;
t2 - t1

t1=cputime;
q = ones(479,1);
B = A - shift*speye(479);
C = full(inv(B));
for j = 1:10 
      q = C * q;
      [bgst,index]=max(abs(q));
      sigma(j+1) = q(index(1));
      q = q/sigma(j+1);
    end
t2 = cputime;
t2 - t1



A = [5 1 1; 1 4 1; 1 1 3];
GJ = [0 -1/5 -1/5; -1/4 0 -1/4; -1/3 -1/3 0]
v = [0; 0; 0];
for j = 2:23
   v = GJ*v + [2; 3; 4];
   r(j) = norm([10; 12; 12] - A*v,2);
end 
r(2:23)
v


DplusLinv=inv([5 0 0; 1 4 0; 1 1 3]);
GGS = -DplusLinv*[0 1 1; 0 0 1; 0 0 0];
v = [0; 0; 0];
for j = 2:9
   v = GGS*v + DplusLinv*[10; 12; 12];
   r(j) = norm([10; 12; 12] - A*v,2);
end 
r(2:9)
v
