# NLA-3.2

## 2082 days 전, jhlee2chn 작성

Algorithm 3.2.1  Householder transformation

from numpy import * x=array([1.0, 0.0, 4.0, 6.0, 3.0, 4.0]) print "x=", x def householder(x): n=len(x) # 벡터 x의 길이 v=zeros(n) eta=linalg.norm(x, inf) x=x/eta sig=linalg.norm(x[1:n]) v[0]=1;v[1:n]=x[1:n] if sig!=0: alp=sqrt(square(x[0])+sig) if x[0]<=0: v[0]=x[0]-alp else: v[0]=-sig/(x[0]+alp) beta=2*square(v[0])/(sig+square(v[0])) v=v/v[0] else: beta=0 print "v=", v print "beta=", beta householder(x)
 x= [ 1. 0. 4. 6. 3. 4.] v= [ 1. -0. -0.63245092 -0.94867638 -0.47433819 -0.63245092] beta= 0.863473800241 x= [ 1. 0. 4. 6. 3. 4.] v= [ 1. -0. -0.63245092 -0.94867638 -0.47433819 -0.63245092] beta= 0.863473800241

Algorithm 3.2.2  Givens transformation

from numpy import * a=5.0 b=12.0 print "a=", a print "b=", b def givens(a, b): if b!=0: if abs(b)>abs(a): tau=a/b;s=1/sqrt(1+square(tau));c=s*tau else: tau=b/a;c=1/sqrt(1+square(tau));s=c*tau else: c=1.0;s=0.0 r=a*c+b*s print "c=", c print "s=", s print "r=", r givens(a, b)
 a= 5.0 b= 12.0 c= 0.384615384615 s= 0.923076923077 r= 13.0 a= 5.0 b= 12.0 c= 0.384615384615 s= 0.923076923077 r= 13.0