4주차 강의

15 days 전, mindo 작성

# 예제 10 # 치환 S = vector([5,1,2,4,3]) PS = Permutation(S) print PS.inversions() # 반전이 일어난 부분 찾기 print PS.number_of_inversions() # 반전의 개수 구하기 print PS.is_even() # 짝치환인지 확인 
       
[(1, 2), (1, 3), (1, 4), (1, 5), (4, 5)]
5
False
[(1, 2), (1, 3), (1, 4), (1, 5), (4, 5)]
5
False
# 예제 11 행렬식 구하기 B = matrix([[1,2,3],[-4,5,6],[7,-8,9]]) B.det() # 행렬식 
       
240
240
# 가역행렬 성질 A = random_matrix(QQ, 3, 3) B = random_matrix(QQ, 3, 3) AB = A*B print '|AB|=|A||B|', AB.det() == A.det()*B.det() print '|A|=', A.det() if A.det != 0: print 'Is A invertible?', A.is_invertible() print '|A^-1|=|A|^-1?', 1/A.det() == A.inverse().det() else: print 'Is A invertible?', A.is_invertible() 
       
|AB|=|A||B| True
|A|= -6
Is A invertible? True
|A^-1|=|A|^-1? True
|AB|=|A||B| True
|A|= -6
Is A invertible? True
|A^-1|=|A|^-1? True
# 예제 12 # 행렬식, 수반행렬로 역행렬 구하기 A = matrix([[3,-2,1],[5,6,2],[1,0,-3]]) dA = A.det() # 행렬식 adjA = A.adjoint() # 수반행렬 print 'inverse of A=' print (1/dA)*adjA # 역행렬 
       
inverse of A=
[  9/47   3/47   5/47]
[-17/94   5/47   1/94]
[  3/47   1/47 -14/47]
inverse of A=
[  9/47   3/47   5/47]
[-17/94   5/47   1/94]
[  3/47   1/47 -14/47]
# 예제 1 # 일차독립 판정법을 이용한 정사각행렬의 일차독립 판단 x1 = vector([1,2,3]) x2 = vector([-1,0,2]) x3 = vector([3,1,1]) A = column_matrix([x1,x2,x3]) print A print det(A) 
       
[ 1 -1  3]
[ 2  0  1]
[ 3  2  1]
9
[ 1 -1  3]
[ 2  0  1]
[ 3  2  1]
9
# 예제 2 # 동차연립방정식의 해공간 구하기 A = matrix([[4,12,-7,6], [1,3,-2,1], [3,9,-2,11]]) print A.right_kernel() # 행렬 A의 해공간 
       
Free module of degree 4 and rank 2 over Integer Ring
Echelon basis matrix:
[ 1  3  4 -2]
[ 0  5  6 -3]
Free module of degree 4 and rank 2 over Integer Ring
Echelon basis matrix:
[ 1  3  4 -2]
[ 0  5  6 -3]
# 예제 3 # 행렬 A의 rank, nullity 구하기 A = matrix([[1,-2,1,1,2],[-1,3,0,2,-1],[0,1,1,3,4],[1,2,5,13,5]]) print A.rank() print A.right_nullity() 
       
3
2
3
2
# 과제1 # 행렬의 행렬식 구하기 # B = matrix([[1,0,1,0],[2,1,0,-1],[4,0,1,1],[3,0,1,1]]) B = random_matrix(QQ, 7, 7) print 'B=' print B print 'B.det()=', B.det() 
       
B=
[  -1   -2    0    0    0   -1   -1]
[  -1 -1/2    2    0    1    0    2]
[   1   -2    0    0    0    0    1]
[   0    1    0  1/2    2    2   -2]
[  -2   -1    0    0   -1    0    0]
[   1    0    2    1    1    2    0]
[  -2    1    1    0    1    1    1]
B.det()= -41/4
RREF(B)=
[1 0 0 0 0 0 0]
[0 1 0 0 0 0 0]
[0 0 1 0 0 0 0]
[0 0 0 1 0 0 0]
[0 0 0 0 1 0 0]
[0 0 0 0 0 1 0]
[0 0 0 0 0 0 1]
B=
[  -1   -2    0    0    0   -1   -1]
[  -1 -1/2    2    0    1    0    2]
[   1   -2    0    0    0    0    1]
[   0    1    0  1/2    2    2   -2]
[  -2   -1    0    0   -1    0    0]
[   1    0    2    1    1    2    0]
[  -2    1    1    0    1    1    1]
B.det()= -41/4
RREF(B)=
[1 0 0 0 0 0 0]
[0 1 0 0 0 0 0]
[0 0 1 0 0 0 0]
[0 0 0 1 0 0 0]
[0 0 0 0 1 0 0]
[0 0 0 0 0 1 0]
[0 0 0 0 0 0 1]
# 과제2 # 수반행렬로 행렬의 역행렬 구하기 #A = matrix([[-23,475,-19],[51,10,32],[200,35,-14]]) A = random_matrix(QQ, 7, 7) dA = A.det() adjA = A.adjoint() print 'A=' print A inverseA = (1/dA)*adjA print 'inverse of A=' print inverseA 
       
A=
[  -1 -1/2    1    0    0    2 -1/2]
[   2    2    2    0   -1   -1    1]
[   0   -1    0    0    0    1    2]
[ 1/2   -1    0 -1/2    0    0    2]
[   2    0 -1/2    1    0 -1/2    0]
[   2    1   -1    2    0    1   -2]
[   1    1    0   -2 -1/2    1    1]
inverse of A=
[   -3   9/2 -61/2    60   -44    28    -9]
[  -14    19  -125   248  -186   117   -38]
[   -8    12   -79   156  -116    73   -24]
[    1  -3/2  23/2   -22    16   -10     3]
[  -54    75  -501   992  -740   466  -152]
[   -2     3   -20    40   -30    19    -6]
[   -6     8   -52   104   -78    49   -16]
A=
[  -1 -1/2    1    0    0    2 -1/2]
[   2    2    2    0   -1   -1    1]
[   0   -1    0    0    0    1    2]
[ 1/2   -1    0 -1/2    0    0    2]
[   2    0 -1/2    1    0 -1/2    0]
[   2    1   -1    2    0    1   -2]
[   1    1    0   -2 -1/2    1    1]
inverse of A=
[   -3   9/2 -61/2    60   -44    28    -9]
[  -14    19  -125   248  -186   117   -38]
[   -8    12   -79   156  -116    73   -24]
[    1  -3/2  23/2   -22    16   -10     3]
[  -54    75  -501   992  -740   466  -152]
[   -2     3   -20    40   -30    19    -6]
[   -6     8   -52   104   -78    49   -16]