NLA-2.5

2094 days 전, jhlee2chn 작성

Algorithm 2.5.1  Estimating 1-norm of matrix

from numpy import * B = array([[4.0, -2.0, 4.0, 2.0], [-2.0, 10.0, -2.0, -7.0], [4.0, -2.0, 8.0, 4.0], [2.0, -7.0, 4.0, 7.0]]) x = array([0.25, 0.25, 0.25, 0.25]) print "B = " print B print print "x=" print x print k = 1 while k != 0: w = dot(B, x) v = sign(w) z = dot(B.transpose(), v) if linalg.norm(z, inf) <= dot(z, x): nu = linalg.norm(w, 1) k = 0 else: s = ndarray.argmax(abs(z)) x = identity(4)[:, s] k = 1 print nu 
       
B = 
[[  4.  -2.   4.   2.]
 [ -2.  10.  -2.  -7.]
 [  4.  -2.   8.   4.]
 [  2.  -7.   4.   7.]]

x=
[ 0.25  0.25  0.25  0.25]

21.0
B = 
[[  4.  -2.   4.   2.]
 [ -2.  10.  -2.  -7.]
 [  4.  -2.   8.   4.]
 [  2.  -7.   4.   7.]]

x=
[ 0.25  0.25  0.25  0.25]

21.0