%shifted inverse power method for finding eigenvalues 
%of A close to a given number mu

A = [1,2,3;4,5,6;7,8,10];
n = 10;        %number of iterations
x = [1;2;3]; 
u = [1,1,1]; 
mu = -1;       %look for eigenvalues close to mu

[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

disp('corresponding eigenvector is...')
x