7.2 행렬의 곱

72 days 전, namy0727 작성

7.2 행렬의 곱


예제 1 행렬의 곱

행렬 $A$와 $B$

A = matrix([[3,5,-1], [4,0,2], [-6,-3,2]]) B = matrix([[2,-2,3,1], [5,0,7,8], [9,-4,1,1]]) print "A=" show(A) print "B=" show(B) 
       
A=

B=
A=

B=

행렬곱 $AB$

print "AB = " show(A*B) 
       
AB = 
AB = 

행렬곱 $AB$ 2행 3열의 성분 $c_{23}$

A2 = Matrix(1,3,[4,0,2]) b3 = Matrix(3,1,[3,7,1]) print "A2=" show(A2) print "b3=" show(b3) print "A2b3 = " show(A2*b3) 
       
A2=

b3=

A2b3 = 
A2=

b3=

A2b3 = 

정의되지 않는 행렬곱 $BA$

print "BA = " show(B*A) 
       
BA = 
Traceback (click to the left of this block for traceback)
...
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 3
by 4 dense matrices over Integer Ring' and 'Full MatrixSpace of 3 by 3
dense matrices over Integer Ring'
BA = 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_23.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("cHJpbnQgIkJBID0gIgpzaG93KEIqQSk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpvHG9qa/___code___.py", line 3, in <module>
    exec compile(u'show(B*A)
  File "", line 1, in <module>
    
  File "element.pyx", line 2751, in sage.structure.element.Matrix.__mul__ (sage/structure/element.c:19587)
  File "coerce.pyx", line 856, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/coerce.c:8169)
TypeError: unsupported operand parent(s) for '*': 'Full MatrixSpace of 3 by 4 dense matrices over Integer Ring' and 'Full MatrixSpace of 3 by 3 dense matrices over Integer Ring'

예제 2 행렬과 벡터의 곱

행렬 $A$와 벡터 $\mathbf{b}$

A = matrix([[4,2],[1,8]]) b = vector([3,5]) print "A=" show(A) print "b=" show(b) 
       
A=

b=
A=

b=

행렬과 벡터의 곱 $A \mathbf{b}$

print "Ab = " show(A*b) 
       
Ab = 
Ab = 

정의되지 않는 행렬과 벡터의 곱 $\mathbf{b}A$

print "b*A = " show(b*A) #Confirm an error 
       
b*A = 
b*A = 

예제 3 행벡터와 열벡터의 곱

행벡터 $\mathbf{a}$와 열벡터 $\mathbf{b}$

a = Matrix(1,3,[3,6,1]) b = Matrix(3,1,[1,2,4]) print "a=" show(a) print "b=" show(b) 
       
a=

b=
a=

b=

벡터곱 $\mathbf{a} \mathbf{b}$

print "ab = " show(a*b) 
       
ab = 
ab = 

벡터곱 $\mathbf{b} \mathbf{a}$

print "ba = " show(b*a) 
       
ba = 
ba = 

예제 4 행렬의 곱은 비가환적이다. 즉 일반적으로 $AB \neq BA$이다.

행렬 $A$와 $B$

A = matrix([[1,1],[100,100]]) B = matrix([[-1,1],[1,-1]]) print "A=" show(A) print "B=" show(B) 
       
A=

B=
A=

B=

행렬곱 $AB$

print "AB = " show(A*B) 
       
AB = 
AB = 

행렬곱 $BA$

print "BA = " show(B*A) 
       
BA = 
BA = 

예제 6 행렬단위 곱계산

행렬 $A$와 $B$

A = matrix([[4,1],[-5,2]]) B = Matrix([[3,0,7],[-1,4,6]]) print "A=" show(A) print "B=" show(B) 
       
A=

B=
A=

B=

행렬 $A$와 행렬 $B$의 첫 번째 열벡터 $\mathbf{b_1}$의 곱 

b1 = Matrix(2,1,[3,-1]) print "b1=" show(b1) print "Ab1=" show(A*b1) 
       
b1=

Ab1=
b1=

Ab1=

행렬 $A$와 행렬 $B$의 두 번째 열벡터 $\mathbf{b_2}$의 곱

b2 = Matrix(2,1,[0,4]) print "b2=" show(b2) print "Ab2=" show(A*b2) 
       
b2=

Ab2=
b2=

Ab2=

행렬 $A$와 행렬 $B$의 세 번째 열벡터 $\mathbf{b_3}$의 곱

b3 = Matrix(2,1,[7,6]) print "b3=" show(b3) print "Ab3=" show(A*b3) 
       
b3=

Ab3=
b3=

Ab3=

행렬곱 $AB$

print "AB=" show(A*B) 
       
AB=
AB=

예제 7 행렬과 벡터의 전치(transpose)

행렬 $A$

A = Matrix([[5,-8,1],[4,0,0]]) print "A=" show(A) 
       
A=
A=

전치행렬 $A^T$

print "Transpose of A=" At=A.transpose() show(At) 
       
Transpose of A=
Transpose of A=

행렬 $B$

B = Matrix([[3,0,7],[8,-1,5],[1,-9,5]]) print "B=" show(B) 
       
B=
B=

전치행렬 $B^T$

print "Transpose of B=" Bt=B.transpose() show(Bt) 
       
Transpose of B=
Transpose of B=

예제 8 대칭행렬과 반대칭행렬

대칭행렬 $A$. 즉 $A^T = A$. 

A = Matrix([[20,120,200],[120,10,150],[200,150,30]]) print "A=" show(A) print "Transpose of A = " At=A.transpose() show(At) 
       
A=

Transpose of A = 
A=

Transpose of A = 

 반대칭행렬 $B$. 즉 $B^T = -B$. 

B = Matrix([[0,1,-3],[-1,0,-2],[3,2,0]]) print "B=" show(B) print "Transpose of B = " Bt=B.transpose() show(Bt) print "= -B" 
       
B=

Transpose of B = 

= -B
B=

Transpose of B = 

= -B

예제 9 위삼각행렬, 아래삼각행렬

위삼각행렬

U1 = Matrix([[1,3],[0,2]]) U2 = Matrix([[1,4,2],[0,3,2],[0,0,6]]) show(U1) show(U2) 
       

아래삼각행렬

L1 = Matrix([[2,0,0],[8,-1,0],[7,6,8]]) L2 = Matrix([[3,0,0,0],[9,-3,0,0],[1,0,2,0],[1,9,3,6]]) show(L1) show(L2) 
       

예제 10 대각행렬, 스칼라행렬, 단위행렬

대각행렬 $D$

D = Matrix([[2,0,0],[0,-3,0],[0,0,0]]) print "D=" show(D) 
       
D=
D=

스칼라행렬 $S$

c = var('c') S = Matrix([[c,0,0],[0,c,0],[0,0,c]]) print "S=" show(S) 
       
S=
S=

단위행렬 $I$

I = identity_matrix(3) print "I=" show(I) 
       
I=
I=

임의의 행렬 $A$

A = random_matrix(QQ,3,3) print "A=" show(A) 
       
A=
A=

행렬 $A$와 스칼라행렬 $S$의 곱

$$AS = SA = cA$$

show(A*S) 
       

행렬 $A$와 단위행렬 $I$의 곱

$$AI = IA = A$$

 

show(I*A)