# NLA-6.2

## 2060 days 전, jhlee2chn 작성

Algorithm 6.2  (power method)

from numpy import argmax,argmin A=matrix([[4,-5],[2,-3]]) x0=vector([0.0,1.0]) # Initial guess of eigenvector maxit=20 # Maximum number of iterates dig=8 # number of decimal places to be shown is dig-1 tol=0.0001 # Tolerance limit for difference of two consecutive eigenvectors err=1 # Initialization of tolerance i=0 r = [] s = [] while(i<=maxit and err>=tol): y0=A*x0 ymod=y0.apply_map(abs) imax=argmax(ymod) c1=y0[imax] x1=y0/c1 r.append((i, c1)) # plot c1 s.append((i, x1[1])) # plot x1[1] err=norm(x0-x1) i=i+1 x0=x1 print "Iteration Number:", i-1 print "y"+str(i-1)+"=",y0.n(digits=dig), "c"+str(i-1)+"=", c1.n(digits=dig), "x"+str(i)+"=",x0.n(digits=dig) show(line2d(r)+point(r, color='red')) show(line2d(s)+point(s, color='red'))
 Iteration Number: 0 y0= (-5.0000000, -3.0000000) c0= -5.0000000 x1= (1.0000000, 0.60000000) Iteration Number: 1 y1= (1.0000000, 0.20000000) c1= 1.0000000 x2= (1.0000000, 0.20000000) Iteration Number: 2 y2= (3.0000000, 1.4000000) c2= 3.0000000 x3= (1.0000000, 0.46666667) Iteration Number: 3 y3= (1.6666667, 0.60000000) c3= 1.6666667 x4= (1.0000000, 0.36000000) Iteration Number: 4 y4= (2.2000000, 0.92000000) c4= 2.2000000 x5= (1.0000000, 0.41818182) Iteration Number: 5 y5= (1.9090909, 0.74545455) c5= 1.9090909 x6= (1.0000000, 0.39047619) Iteration Number: 6 y6= (2.0476190, 0.82857143) c6= 2.0476190 x7= (1.0000000, 0.40465116) Iteration Number: 7 y7= (1.9767442, 0.78604651) c7= 1.9767442 x8= (1.0000000, 0.39764706) Iteration Number: 8 y8= (2.0117647, 0.80705882) c8= 2.0117647 x9= (1.0000000, 0.40116959) Iteration Number: 9 y9= (1.9941520, 0.79649123) c9= 1.9941520 x10= (1.0000000, 0.39941349) Iteration Number: 10 y10= (2.0029326, 0.80175953) c10= 2.0029326 x11= (1.0000000, 0.40029283) Iteration Number: 11 y11= (1.9985359, 0.79912152) c11= 1.9985359 x12= (1.0000000, 0.39985348) Iteration Number: 12 y12= (2.0007326, 0.80043956) c12= 2.0007326 x13= (1.0000000, 0.40007323) Iteration Number: 13 y13= (1.9996338, 0.79978030) c13= 1.9996338 x14= (1.0000000, 0.39996338) Iteration Number: 14 y14= (2.0001831, 0.80010987) c14= 2.0001831 x15= (1.0000000, 0.40001831)  Iteration Number: 0 y0= (-5.0000000, -3.0000000) c0= -5.0000000 x1= (1.0000000, 0.60000000) Iteration Number: 1 y1= (1.0000000, 0.20000000) c1= 1.0000000 x2= (1.0000000, 0.20000000) Iteration Number: 2 y2= (3.0000000, 1.4000000) c2= 3.0000000 x3= (1.0000000, 0.46666667) Iteration Number: 3 y3= (1.6666667, 0.60000000) c3= 1.6666667 x4= (1.0000000, 0.36000000) Iteration Number: 4 y4= (2.2000000, 0.92000000) c4= 2.2000000 x5= (1.0000000, 0.41818182) Iteration Number: 5 y5= (1.9090909, 0.74545455) c5= 1.9090909 x6= (1.0000000, 0.39047619) Iteration Number: 6 y6= (2.0476190, 0.82857143) c6= 2.0476190 x7= (1.0000000, 0.40465116) Iteration Number: 7 y7= (1.9767442, 0.78604651) c7= 1.9767442 x8= (1.0000000, 0.39764706) Iteration Number: 8 y8= (2.0117647, 0.80705882) c8= 2.0117647 x9= (1.0000000, 0.40116959) Iteration Number: 9 y9= (1.9941520, 0.79649123) c9= 1.9941520 x10= (1.0000000, 0.39941349) Iteration Number: 10 y10= (2.0029326, 0.80175953) c10= 2.0029326 x11= (1.0000000, 0.40029283) Iteration Number: 11 y11= (1.9985359, 0.79912152) c11= 1.9985359 x12= (1.0000000, 0.39985348) Iteration Number: 12 y12= (2.0007326, 0.80043956) c12= 2.0007326 x13= (1.0000000, 0.40007323) Iteration Number: 13 y13= (1.9996338, 0.79978030) c13= 1.9996338 x14= (1.0000000, 0.39996338) Iteration Number: 14 y14= (2.0001831, 0.80010987) c14= 2.0001831 x15= (1.0000000, 0.40001831) 
A=matrix([[4,-5],[2,-3]]) A.eigenvectors_right()
 [(2, [ (1, 2/5) ], 1), (-1, [ (1, 1) ], 1)] [(2, [ (1, 2/5) ], 1), (-1, [ (1, 1) ], 1)]