% eigen2.m --- inverse iteration method format long a=[1 1 1;1 2 2;1 2 3] eigen=eig(a) x=ones(3,1); maxiter=30; r=zeros(maxiter,1); [L u p]=lu(a); shift=1; for k=1:maxiter y=u\(L\(p*x)); x=y/norm(y); r(k)=x'*(a*x); end r error=r-min(eigen) clf semilogy(1:maxiter,abs(error)) |