clear format long format compact %% % We set up a 5x5 triangular matrix with prescribed eigenvalues on % its diagonal. lambda = [1 -0.75 0.6 -0.4 0]; A = triu(ones(5),1) + diag(lambda); %% % We run RQ iteration with the initial shift s=0.7 and take the final % estimate as our ``exact'' answer to observe the convergence. [gamma, m, x] = rqiter(A, 0.7, 10); eigval = gamma(m) m %% % As expected, the eigenvalue that was found is the one closest to 0.7. err = eigval - gamma; semilogy(abs(err(1:m)),'.-') title('Convergence of inverse iteration') xlabel('k') ylabel('|\lambda_1 - \gamma_k|') grid on