>> A(1,1) = 1; A(2,2) = .9; for i=3:10, A(i,i) = rand/2; end >> A A = Columns 1 through 7 1.0000 0 0 0 0 0 0 0 0.9000 0 0 0 0 0 0 0 0.4751 0 0 0 0 0 0 0 0.1156 0 0 0 0 0 0 0 0.3034 0 0 0 0 0 0 0 0.2430 0 0 0 0 0 0 0 0.4456 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 8 through 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3810 0 0 0 0.2282 0 0 0 0.0093 >> M = rand(10,10); >> A = M*A*inv(M); >> z = ones(10,1); >> for i=1:100, w = A*z; lambda(i) = w(1)/z(1); z = w/max(abs(w)); end >> lambda lambda = Columns 1 through 7 0.3429 0.6372 0.9225 1.0246 1.0403 1.0369 1.0314 Columns 8 through 14 1.0267 1.0229 1.0200 1.0175 1.0154 1.0137 1.0121 Columns 15 through 21 1.0108 1.0096 1.0085 1.0076 1.0068 1.0061 1.0054 Columns 22 through 28 1.0049 1.0044 1.0039 1.0035 1.0031 1.0028 1.0025 Columns 29 through 35 1.0023 1.0020 1.0018 1.0016 1.0015 1.0013 1.0012 Columns 36 through 42 1.0011 1.0010 1.0009 1.0008 1.0007 1.0006 1.0006 Columns 43 through 49 1.0005 1.0005 1.0004 1.0004 1.0003 1.0003 1.0003 Columns 50 through 56 1.0002 1.0002 1.0002 1.0002 1.0002 1.0001 1.0001 Columns 57 through 63 1.0001 1.0001 1.0001 1.0001 1.0001 1.0001 1.0001 Columns 64 through 70 1.0001 1.0001 1.0000 1.0000 1.0000 1.0000 1.0000 Columns 71 through 77 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 Columns 78 through 84 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 Columns 85 through 91 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 Columns 92 through 98 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 Columns 99 through 100 1.0000 1.0000 >> format short e >> err = abs(1-lambda) err = Columns 1 through 6 6.5709e-01 3.6285e-01 7.7459e-02 2.4631e-02 4.0320e-02 3.6894e-02 Columns 7 through 12 3.1354e-02 2.6655e-02 2.2941e-02 1.9962e-02 1.7506e-02 1.5433e-02 Columns 13 through 18 1.3655e-02 1.2113e-02 1.0766e-02 9.5844e-03 8.5430e-03 7.6232e-03 Columns 19 through 24 6.8087e-03 6.0863e-03 5.4445e-03 4.8735e-03 4.3649e-03 3.9113e-03 Columns 25 through 30 3.5065e-03 3.1448e-03 2.8214e-03 2.5322e-03 2.2732e-03 2.0412e-03 Columns 31 through 36 1.8334e-03 1.6470e-03 1.4799e-03 1.3299e-03 1.1953e-03 1.0745e-03 Columns 37 through 42 9.6602e-04 8.6858e-04 7.8104e-04 7.0239e-04 6.3171e-04 5.6818e-04 Columns 43 through 48 5.1107e-04 4.5973e-04 4.1357e-04 3.7206e-04 3.3473e-04 3.0115e-04 Columns 49 through 54 2.7096e-04 2.4379e-04 2.1936e-04 1.9738e-04 1.7761e-04 1.5982e-04 Columns 55 through 60 1.4381e-04 1.2941e-04 1.1646e-04 1.0480e-04 9.4310e-05 8.4871e-05 Columns 61 through 66 7.6377e-05 6.8734e-05 6.1857e-05 5.5667e-05 5.0098e-05 4.5086e-05 Columns 67 through 72 4.0575e-05 3.6516e-05 3.2864e-05 2.9576e-05 2.6618e-05 2.3955e-05 Columns 73 through 78 2.1559e-05 1.9403e-05 1.7462e-05 1.5716e-05 1.4144e-05 1.2729e-05 Columns 79 through 84 1.1456e-05 1.0311e-05 9.2795e-06 8.3514e-06 7.5162e-06 6.7646e-06 Columns 85 through 90 6.0881e-06 5.4792e-06 4.9313e-06 4.4381e-06 3.9943e-06 3.5948e-06 Columns 91 through 96 3.2354e-06 2.9118e-06 2.6206e-06 2.3586e-06 2.1227e-06 1.9104e-06 Columns 97 through 100 1.7194e-06 1.5474e-06 1.3927e-06 1.2534e-06 >> tol = 1.e-10; >> z = ones(10,1); >> i = 1; test = 2*tol; while test > tol w = A*z; lambda(i) = w(1)/z(1); z = w/max(abs(w)); test = abs(lambda(i)-1); i = i+1; end check that we reached the tolerance: >> test test = 9.5482e-11 how many iterations did it take? >> i i = 191 >> diary off