%Section 8.4 #4

A = [-57,192,148;20,-53,-44;-48,144,115];
n = 10;        %number of iterations
mus = [-4,2,8];

for i=1:3
    
x = [1;2;3]; 
u = [1,1,0]; 

mu = mus(i);     

[L,U] = lu(A-mu*eye(3));   %LU factorization is used to avoid inverting A

for i=1:n
    z = linsolve(L,x);
    y = linsolve(U,z);
    r = (u*y)/(u*x);
    x = y/max(abs(y));
end

disp('estimate of eigenvalue close to mu is...')
mu + 1/r

end