6주차 강의

64 days 전, mindo 작성

# 예제 1 - 선형변환 T의 표준행렬 구하기 var('x, y, z') h(x, y, z) = [x + 2*y, -x-y, z, x+z] # 함수의 정의 T = linear_transformation(QQ^3, QQ^4, h) # 선형변환 정의, 스칼라는 유리수, 3->4 e1 = vector([1,0,0]) # R^3의 단위벡터 생성 e2 = vector([0,1,0]) e3 = vector([0,0,1]) column_matrix([T(e1), T(e2), T(e3)]) # T의 표준행렬 
       
[ 1  2  0]
[-1 -1  0]
[ 0  0  1]
[ 1  0  1]
[ 1  2  0]
[-1 -1  0]
[ 0  0  1]
[ 1  0  1]
# 예제 2 - 선형변환 T의 표준행렬을 이용해 T(x)=Ax로 표시하기 var('x, y, z') h(x,y,z) = [x+2*y, -x-y, z, x+z] # 함수의 정의 T = linear_transformation(QQ^3, QQ^4, h) # 선형변환 정의, 스칼라는 유리수, 3->4 A = T.matrix(side = 'right') # 선형변환의 표준행렬 구하기 x0 = random_vector(3) #임의의 벡터 x0 print 'A=' print A print print 'T(x0)=', T(x0) print 'A*x0=', A*x0 
       
A=
[ 1  2  0]
[-1 -1  0]
[ 0  0  1]
[ 1  0  1]

T(x0)= (16, -16, 2, 18)
A*x0= (16, -16, 2, 18)
A=
[ 1  2  0]
[-1 -1  0]
[ 0  0  1]
[ 1  0  1]

T(x0)= (16, -16, 2, 18)
A*x0= (16, -16, 2, 18)
# 예제 3 - T의 kernel을 구하고, T가 단사인지 확인하기 var('x,y,z') U = QQ^3 # 벡터공간 정의 h(x,y,z) = [x+2*y-z, y+z, x+y-2*z] # 선형변환 함수 T = linear_transformation(U, U, h) # 선형변환 생성 print T TK = T.kernel() # kernel 구하기 print TK print 'T is injective?', T.is_injective() # 단사인지 확인하기 
       
Vector space morphism represented by the matrix:
[ 1  0  1]
[ 2  1  1]
[-1  1 -2]
Domain: Vector space of dimension 3 over Rational Field
Codomain: Vector space of dimension 3 over Rational Field
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[   1 -1/3  1/3]
T is injective? False
Vector space morphism represented by the matrix:
[ 1  0  1]
[ 2  1  1]
[-1  1 -2]
Domain: Vector space of dimension 3 over Rational Field
Codomain: Vector space of dimension 3 over Rational Field
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[   1 -1/3  1/3]
T is injective? False
# 예제 4 - T는 단사이지만 전사는 아님을 보여라 U = QQ^2 # 벡터공간 정의 V = QQ^3 # 벡터공간 정의 A = matrix(QQ, [[1,0], [0,1],[0,0]]) # 변환행렬 정의 TA = linear_transformation(U, V, A, side='right') # 선형변환 print TA print TA.kernel() # kernel 구하기 print 'TA is injective?', TA.is_injective() # 단사인지 확인 print TA.image() # 치역 구하기 print 'TA is surjective?', TA.is_surjective() # 전사인지 확인 
       
Vector space morphism represented by the matrix:
[1 0 0]
[0 1 0]
Domain: Vector space of dimension 2 over Rational Field
Codomain: Vector space of dimension 3 over Rational Field
Vector space of degree 2 and dimension 0 over Rational Field
Basis matrix:
[]
TA is injective? True
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[1 0 0]
[0 1 0]
TA is surjective? False
Vector space morphism represented by the matrix:
[1 0 0]
[0 1 0]
Domain: Vector space of dimension 2 over Rational Field
Codomain: Vector space of dimension 3 over Rational Field
Vector space of degree 2 and dimension 0 over Rational Field
Basis matrix:
[]
TA is injective? True
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[1 0 0]
[0 1 0]
TA is surjective? False
# 예제 T1, T2의 합성변환 V = QQ[sqrt(2)]^2 x, y = var('x, y') # 변수 선언 h(x, y) = [3*x, 2*y] A = matrix([[cos(pi/4), -sin(pi/4)], [sin(pi/4), cos(pi/4)]]) T = linear_transformation(V, V, h) # 선형변환(직접) S = linear_transformation(V, V, A, side='right') # 선형변환(행렬) # S 만드는 부분에서 에러 # TypeError: <type 'sage.symbolic.expression.Expression'> U = S*T # 합성함수 C = U.matrix(side='right') #표준행렬 구하기 print C # sage cell server에서는 정상작동함 # 결과 # [3/2*sqrt2 -sqrt2] # [3/2*sqrt2 sqrt2] 
       
Traceback (click to the left of this block for traceback)
...
TypeError: <type 'sage.symbolic.expression.Expression'>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_22.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("IyDsmIjsoJwgVDEsIFQy7J2YIO2VqeyEseuzgO2ZmApWID0gUVFbc3FydCgyKV1eMgp4LCB5ID0gdmFyKCd4LCB5JykgIyDrs4DsiJgg7ISg7Ja4CmgoeCwgeSkgPSBbMyp4LCAyKnldCkEgPSBtYXRyaXgoW1tjb3MocGkvNCksIC1zaW4ocGkvNCldLCBbc2luKHBpLzQpLCBjb3MocGkvNCldXSkKVCA9IGxpbmVhcl90cmFuc2Zvcm1hdGlvbihWLCBWLCBoKSAjIOyEoO2YleuzgO2ZmCjsp4HsoJEpClMgPSBsaW5lYXJfdHJhbnNmb3JtYXRpb24oViwgViwgQSwgc2lkZT0ncmlnaHQnKSAjIOyEoO2YleuzgO2ZmCjtlonroKwpCiMgUyDrp4zrk5zripQg67aA67aE7JeQ7IScIOyXkOufrAojIFR5cGVFcnJvcjogPHR5cGUgJ3NhZ2Uuc3ltYm9saWMuZXhwcmVzc2lvbi5FeHByZXNzaW9uJz4KClUgPSBTKlQgIyDtlanshLHtlajsiJgKQyA9IFUubWF0cml4KHNpZGU9J3JpZ2h0JykgI+2RnOykgO2WieugrCDqtaztlZjquLAKcHJpbnQgQwoKIyBzYWdlIGNlbGwgc2VydmVy7JeQ7ISc64qUIOygleyDgeyekeuPme2VqAojIOqysOqzvAojIFszLzIqc3FydDIgICAgLXNxcnQyXQojIFszLzIqc3FydDIgICAgIHNxcnQyXQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpe0yqih/___code___.py", line 8, in <module>
    S = linear_transformation(V, V, A, side='right') # 선형변환(행렬)
  File "/usr/local/sage-5.12/local/lib/python2.7/site-packages/sage/modules/vector_space_morphism.py", line 770, in linear_transformation
    return H(arg2)
  File "/usr/local/sage-5.12/local/lib/python2.7/site-packages/sage/modules/vector_space_homspace.py", line 395, in __call__
    return VectorSpaceMorphism(self, A)
  File "/usr/local/sage-5.12/local/lib/python2.7/site-packages/sage/modules/vector_space_morphism.py", line 865, in __init__
    A = homspace._matrix_space()(A)
  File "/usr/local/sage-5.12/local/lib/python2.7/site-packages/sage/matrix/matrix_space.py", line 507, in __call__
    return self.matrix(entries, coerce, copy)
  File "/usr/local/sage-5.12/local/lib/python2.7/site-packages/sage/matrix/matrix_space.py", line 1378, in matrix
    return MC(self, x, copy=copy, coerce=coerce) 
  File "matrix_generic_dense.pyx", line 109, in sage.matrix.matrix_generic_dense.Matrix_generic_dense.__init__ (sage/matrix/matrix_generic_dense.c:2764)
  File "parent.pyx", line 1009, in sage.structure.parent.Parent.__call__ (sage/structure/parent.c:8372)
  File "coerce_maps.pyx", line 82, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3856)
  File "coerce_maps.pyx", line 77, in sage.structure.coerce_maps.DefaultConvertMap_unique._call_ (sage/structure/coerce_maps.c:3757)
  File "/usr/local/sage-5.12/local/lib/python2.7/site-packages/sage/rings/number_field/number_field.py", line 1247, in _element_constructor_
    return self._coerce_non_number_field_element_in(x)
  File "/usr/local/sage-5.12/local/lib/python2.7/site-packages/sage/rings/number_field/number_field.py", line 5872, in _coerce_non_number_field_element_in
    raise TypeError, type(x)
TypeError: <type 'sage.symbolic.expression.Expression'>
 
       
# 6주차 과제 1 # 일차독립인지 일차종속인지 결정하라 v1 = vector(QQ, [4,-5,2,6]) v2 = vector(QQ, [2,-2,1,3]) v3 = vector(QQ, [6,-3,3,9]) v4 = vector(QQ, [4,-1,5,6]) N = 7 v1 = random_vector(QQ, N) v2 = random_vector(QQ, N) v3 = random_vector(QQ, N) v4 = random_vector(QQ, N) v5 = random_vector(QQ, N) v6 = random_vector(QQ, N) v7 = random_vector(QQ, N) A = column_matrix([v1, v2, v3, v4, v5, v6, v7]) print A # 1) 열의 개수와 열공간을 생성하는 벡터의 개수가 같은지 확인 print 'A.ncols = ', A.ncols() # 열의 개수 print 'A.pivots = ', A.pivots() # 열공간을 생성하는 벡터 print A.ncols() == len(A.pivots()) # True면 일차독립 # 행렬식이 0이 아닌지 확인(단, 정사각행렬일 때) print det(A) != 0 # 3) 일차종속인지 확인 V = QQ^N print V.linear_dependence(A) == [] # True면 일차독립 
       
[   -2    -4  -1/5   1/2     7  -1/2   1/2]
[    7    -2     0    -1     0     0  19/2]
[    3    -3     2    -2  -5/4 101/2   1/6]
[    0  -1/9     1    -1     0     4     2]
[    2   8/5     0     1   2/3  -1/2    -4]
[    1    -1     0  -1/3     0     0     1]
[    0    -1    -1     1   2/5     6  -1/3]
A.ncols =  7
A.pivots =  (0, 1, 2, 3, 4, 5, 6)
True
True
True
[   -2    -4  -1/5   1/2     7  -1/2   1/2]
[    7    -2     0    -1     0     0  19/2]
[    3    -3     2    -2  -5/4 101/2   1/6]
[    0  -1/9     1    -1     0     4     2]
[    2   8/5     0     1   2/3  -1/2    -4]
[    1    -1     0  -1/3     0     0     1]
[    0    -1    -1     1   2/5     6  -1/3]
A.ncols =  7
A.pivots =  (0, 1, 2, 3, 4, 5, 6)
True
True
True
v1 = vector(QQ, [4,-5,2,6]) v2 = vector(QQ, [2,-2,1,3]) v3 = vector(QQ, [6,-3,3,9]) v4 = vector(QQ, [4,-1,5,6]) A = column_matrix([v1, v2, v3, v4]) print A print 'A.ncols = ', A.ncols() # 열의 개수 print 'A.pivots = ', A.pivots() # 열공간을 생성하는 벡터 print A.ncols() == len(A.pivots()) # True면 일차독립 print det(A) # 행렬식이 0이 아니면 일차독립 
       
[ 4  2  6  4]
[-5 -2 -3 -1]
[ 2  1  3  5]
[ 6  3  9  6]
A.ncols =  4
A.pivots =  (0, 1, 3)
False
0
[ 4  2  6  4]
[-5 -2 -3 -1]
[ 2  1  3  5]
[ 6  3  9  6]
A.ncols =  4
A.pivots =  (0, 1, 3)
False
0