© 2001 by CRC Press LLC
should be terminated. To obtain the largest eigenvalue in magnitude, we proceed
directly with a given matrix as follows:
Input[1]: = A = {{2,0,3},{0,5,0},{3,0,2}}; V = {1,0,0}; I = 0;
Input[2]: = While[i<8, I = I + 1; VN = A.V; Lambda = Sqrt[VN.VN];
Print["Iteration # ",I," ","Lambda = ",N[Lambda],
" {V} =",V = N[VN/Lambda]]]
Output[2]: =
Iteration # 1 Lambda = 3.60555 {V} = {0.5547, 0, 0.83205}
Iteration # 2 Lambda = 4.90682 {V} = {0.734803, 0, 0.67828}
Iteration # 3 Lambda = 4.99616 {V} = {0.701427, 0, 0.712741}
Iteration # 4 Lambda = 4.99985 {V} = {0.708237, 0, 0.709575}
Iteration # 5 Lambda = 4.99999 {V} = {0.70688, 0, 0.707333}
Iteration # 6 Lambda = 5. {V} = {0.707152, 0, 0.707062}
Iteration # 7 Lambda = 5. {V} = {0.707098, 0, 0.707016}
Iteration # 8 Lambda = 5. {V} = {0.707109, 0, 0.707105}
Notice that the testing condition is whether the running iteration counter I is
less than 8 or not. This setup enables up to eight iterations to be conducted. The
function N in Input[2] requests the value of the variable inside the brackets to be
given in numerical form. For example, when the value of Lambda is displayed as
sqrt[4], it will be displayed as 2.00000 if the input is N[Lambda]. VA·VB is the dot
product of VA and VB. In Input[2] some sample printouts of the character strings
specified inside a pair of parentheses are also demonstrated.
For iterating the smallest eigenvalue in magnitude, we work on the inverse of
this given matrix as follows:
Input[3]: = Ainv = Inverse[A]; V = {1,0,0}; I = 0;
Input[4]: = While[i<8, I = I + 1; VN = Ainv.V; Lambda = Sqrt[VN.VN];
Print["Iteration # ",I," ","Lambda = ",N[Lambda],
" {V} = ",V = N[VN/Lambda]]]
Output[4]: =
Iteration # 1 Lambda = 0.72111 {V} = {–0.5547, 0, 0.83205}
Iteration # 2 Lambda = 0.981365 {V} = {0.734803, 0, –0.67828}
Iteration # 3 Lambda = 0.999233 {V} = {–0.701427, 0, 0.712741}
Iteration # 4 Lambda = 0.999969 {V} = {0.708237, –0, 0.709575}
Iteration # 5 Lambda = 0.999999 {V} = {–0.70688, 0, 0.707333}
Iteration # 6 Lambda = 1. {V} = {0.707152, 0, –0.707062}
Iteration # 7 Lambda = 1. {V} = {–0.707098, 0, 0.707016}
Iteration # 8 Lambda = 1. {V} = {0.707109, 0, –0.707105}