1주차 강의

60 days 전, mindo 작성

# 예제1 a = vector([1,2,-3,4]) b = vector([-2,4,1,0]) print(a+b) print(a-b) print(-2*a) 
       
(-1, 6, -2, 4)
(3, -2, -4, 4)
(-2, -4, 6, -8)
(-1, 6, -2, 4)
(3, -2, -4, 4)
(-2, -4, 6, -8)
# 예제 2 a = vector([2,-1,3,2]) b = vector([3,2,1,-4]) print(a.norm()) print(b.norm()) print((a-b).norm()) # a-b의 노름 
       
3*sqrt(2)
sqrt(30)
5*sqrt(2)
3*sqrt(2)
sqrt(30)
5*sqrt(2)
# 예제 3 a = vector([2,-1,3,2]) b = vector([3,2,1,-4]) print(a.inner_product(b)) # 내적 a,b 
       
-1
-1
# 예제 4 a = vector([2,-1,3]) b = vector([4,-1,2]) xy = a.inner_product(b) x = a.norm() # a norm || x || xx = x*x # a norm pow # xx = a.inner_product(a) projxy = xy*a/xx print(projxy) w = b - projxy print(w) 
       
(15/7, -15/14, 45/14)
(13/7, 1/14, -17/14)
(15/7, -15/14, 45/14)
(13/7, 1/14, -17/14)
# 예제 5 v = vector([3,-1,2]) n = vector([1,3,-2]) d = -6 nv = n.inner_product(v) print(nv) nn = n.norm() print(nn) D = abs(nv+d)/nn print(D) 
       
-4
sqrt(14)
5/7*sqrt(14)
-4
sqrt(14)
5/7*sqrt(14)
# 과제 1 #x = vector([-1,-2,3]) #y = vector([3,-2,-1]) # random_vector x = random_vector(7, -10, 10) y = random_vector(7, -10, 10) #x = vector([1, -6, 8, -2, 3, -10, -1]) #y = vector([5, -5, -1, 8, 2, -7, -2]) print 'x=', x print 'y=', y # x, y inner product xy = x.inner_product(y) print 'xy=', xy # x norm xn = x.norm() # y norm yn = y.norm() print 'xn=', xn print 'yn=', yn # cos angle cosa = xy/(xn*yn) print 'cos angle=', cosa # arccos angle = (arccos(cosa)).n(digits=5) print 'x, y angle=', angle 
       
x= (0, 2, 1, 4, 0, 0, 2)
y= (-8, -8, 0, 7, -1, 3, 6)
xy= 24
xn= 5
yn= sqrt(223)
cos angle= 24/1115*sqrt(223)
x, y angle= arccos(24/1115*sqrt(223))
x= (0, 2, 1, 4, 0, 0, 2)
y= (-8, -8, 0, 7, -1, 3, 6)
xy= 24
xn= 5
yn= sqrt(223)
cos angle= 24/1115*sqrt(223)
x, y angle= arccos(24/1115*sqrt(223))
# 과제 2 x = vector([2,-1,3]) y = vector([4,-1,2]) # random_vector x = random_vector(7, -10, 10) y = random_vector(7, -10, 10) print 'x=', x print 'y=', y # xy inner product xy = x.inner_product(y) # xx inner product xx = x.inner_product(x) # projection of y onto x p = xy/xx*x print 'p=', p # vector component w w = y - p print 'w=', w 
       
x= (-8, -4, 0, 1, 0, 3, -4)
y= (-3, 1, -1, 0, -6, -8, -7)
p= (-96/53, -48/53, 0, 12/53, 0, 36/53, -48/53)
w= (-63/53, 101/53, -1, -12/53, -6, -460/53, -323/53)
x= (-8, -4, 0, 1, 0, 3, -4)
y= (-3, 1, -1, 0, -6, -8, -7)
p= (-96/53, -48/53, 0, 12/53, 0, 36/53, -48/53)
w= (-63/53, 101/53, -1, -12/53, -6, -460/53, -323/53)