15.2. AUTOMATION WITH MATLAB 415
15.1.2 The Explicit Description Of The MethodHere is how you use this method to find the eigenvalue closest to α and the corre-sponding eigenvector.
1. Find (A−αI)−1 .
2. Pick u1. If you are not phenomenally unlucky, the iterations will converge.
3. If uk has been obtained, uk+1 =(A−αI)−1uk
sk+1where sk+1 is the entry of (A−αI)−1uk
which has largest absolute value.
4. When the scaling factors, sk are not changing much and the uk are not changingmuch, find the approximation to the eigenvalue by solving sk+1 = 1
λ−αfor λ . The
eigenvector is approximated by uk+1.
5. Check your work by multiplying by the original matrix to see how well what youhave found works.
Thus this amounts to the power method for the matrix (A−αI)−1 but you are free topick α .
15.2 Automation With MatlabYou can do the above example and other examples using Matlab. Here are some commandswhich will do this. It is done here for a 3×3 matrix but you adapt for any size.
a=[5 -8 6;1 0 0;0 1 0]; b=i; F=inv(a-b*eye(3));S=1; u=[1;1;1]; d=1; k=1;while d >.00001 & k<1000w=F*u; [M,I]=max(abs(w)); T=w(I); u=w/T;d=abs(T-S); S=T; k=k+1;endub+1/Tka*u-(b+1/T)*u
eye(3) signifies the 3×3 identity. It is less trouble to write this.Note how the “while loop” is limited to 1000 iterations. That way it won’t go on forever
if there is something wrong. This asks for the eigenvalue closest to b = i. When Matlabstalls, to get it to quit, you type control c. The last line checks the answer and the linewith k tells the number of iterations used. Also, the funny notation [M,I]=max(abs(w));T=w(I); gets it to pick out the entry which has largest absolute value w(I) and keep thatentry unchanged. The above iteration finds the eigenvalue closest to i along with the cor-responding eigenvector. When the procedure does not work well for b real, you mightimagine that there are complex eigenvalues and so, since the above procedure is going togive you real approximations, it can’t find the complex eigenvalues. Thus you should takeb to be complex as done above.