# 7.2 행렬의 곱

### 행렬 $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= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 3 & 5 & -1 \\ 4 & 0 & 2 \\ -6 & -3 & 2 \end{array}\right) B= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrrr} 2 & -2 & 3 & 1 \\ 5 & 0 & 7 & 8 \\ 9 & -4 & 1 & 1 \end{array}\right) A= B=

### 행렬곱 $AB$

print "AB = " show(A*B)
 AB = \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrrr} 22 & -2 & 43 & 42 \\ 26 & -16 & 14 & 6 \\ -9 & 4 & -37 & -28 \end{array}\right) 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= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 4 & 0 & 2 \end{array}\right) b3= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{r} 3 \\ 7 \\ 1 \end{array}\right) A2b3 = \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{r} 14 \end{array}\right) 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 "", line 1, in File "_sage_input_23.py", line 10, in 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 File "/tmp/tmpvHG9qa/___code___.py", line 3, in exec compile(u'show(B*A) File "", line 1, in 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'

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

A = matrix([[4,2],[1,8]]) b = vector([3,5]) print "A=" show(A) print "b=" show(b)
 A= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rr} 4 & 2 \\ 1 & 8 \end{array}\right) b= \newcommand{\Bold}{\mathbf{#1}}\left(3,\,5\right) A= b=

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

print "Ab = " show(A*b)
 Ab = \newcommand{\Bold}{\mathbf{#1}}\left(22,\,43\right) Ab =

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

print "b*A = " show(b*A) #Confirm an error
 b*A = \newcommand{\Bold}{\mathbf{#1}}\left(17,\,46\right) b*A =

### 행벡터 $\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= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 3 & 6 & 1 \end{array}\right) b= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{r} 1 \\ 2 \\ 4 \end{array}\right) a= b=

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

print "ab = " show(a*b)
 ab = \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{r} 19 \end{array}\right) ab =

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

print "ba = " show(b*a)
 ba = \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 3 & 6 & 1 \\ 6 & 12 & 2 \\ 12 & 24 & 4 \end{array}\right) ba =

### 행렬 $A$와 $B$

A = matrix([[1,1],[100,100]]) B = matrix([[-1,1],[1,-1]]) print "A=" show(A) print "B=" show(B)
 A= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rr} 1 & 1 \\ 100 & 100 \end{array}\right) B= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rr} -1 & 1 \\ 1 & -1 \end{array}\right) A= B=

### 행렬곱 $AB$

print "AB = " show(A*B)
 AB = \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rr} 0 & 0 \\ 0 & 0 \end{array}\right) AB =

### 행렬곱 $BA$

print "BA = " show(B*A)
 BA = \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rr} 99 & 99 \\ -99 & -99 \end{array}\right) BA =

### 행렬 $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= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rr} 4 & 1 \\ -5 & 2 \end{array}\right) B= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 3 & 0 & 7 \\ -1 & 4 & 6 \end{array}\right) A= B=

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

b1 = Matrix(2,1,[3,-1]) print "b1=" show(b1) print "Ab1=" show(A*b1)
 b1= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{r} 3 \\ -1 \end{array}\right) Ab1= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{r} 11 \\ -17 \end{array}\right) b1= Ab1=

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

b2 = Matrix(2,1,[0,4]) print "b2=" show(b2) print "Ab2=" show(A*b2)
 b2= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{r} 0 \\ 4 \end{array}\right) Ab2= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{r} 4 \\ 8 \end{array}\right) b2= Ab2=

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

b3 = Matrix(2,1,[7,6]) print "b3=" show(b3) print "Ab3=" show(A*b3)
 b3= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{r} 7 \\ 6 \end{array}\right) Ab3= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{r} 34 \\ -23 \end{array}\right) b3= Ab3=

### 행렬곱 $AB$

print "AB=" show(A*B)
 AB= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 11 & 4 & 34 \\ -17 & 8 & -23 \end{array}\right) AB=

### 행렬 $A$

A = Matrix([[5,-8,1],[4,0,0]]) print "A=" show(A)
 A= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 5 & -8 & 1 \\ 4 & 0 & 0 \end{array}\right) A=

### 전치행렬 $A^T$

print "Transpose of A=" At=A.transpose() show(At)
 Transpose of A= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rr} 5 & 4 \\ -8 & 0 \\ 1 & 0 \end{array}\right) Transpose of A=

### 행렬 $B$

B = Matrix([[3,0,7],[8,-1,5],[1,-9,5]]) print "B=" show(B)
 B= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 3 & 0 & 7 \\ 8 & -1 & 5 \\ 1 & -9 & 5 \end{array}\right) B=

### 전치행렬 $B^T$

print "Transpose of B=" Bt=B.transpose() show(Bt)
 Transpose of B= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 3 & 8 & 1 \\ 0 & -1 & -9 \\ 7 & 5 & 5 \end{array}\right) Transpose of B=

### 대칭행렬 $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= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 20 & 120 & 200 \\ 120 & 10 & 150 \\ 200 & 150 & 30 \end{array}\right) Transpose of A = \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 20 & 120 & 200 \\ 120 & 10 & 150 \\ 200 & 150 & 30 \end{array}\right) 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= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 0 & 1 & -3 \\ -1 & 0 & -2 \\ 3 & 2 & 0 \end{array}\right) Transpose of B = \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 0 & -1 & 3 \\ 1 & 0 & 2 \\ -3 & -2 & 0 \end{array}\right) = -B B= Transpose of B = = -B

### 위삼각행렬

U1 = Matrix([[1,3],[0,2]]) U2 = Matrix([[1,4,2],[0,3,2],[0,0,6]]) show(U1) show(U2)
 \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rr} 1 & 3 \\ 0 & 2 \end{array}\right) \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 1 & 4 & 2 \\ 0 & 3 & 2 \\ 0 & 0 & 6 \end{array}\right)

### 아래삼각행렬

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)
 \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 2 & 0 & 0 \\ 8 & -1 & 0 \\ 7 & 6 & 8 \end{array}\right) \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrrr} 3 & 0 & 0 & 0 \\ 9 & -3 & 0 & 0 \\ 1 & 0 & 2 & 0 \\ 1 & 9 & 3 & 6 \end{array}\right)

### 대각행렬 $D$

D = Matrix([[2,0,0],[0,-3,0],[0,0,0]]) print "D=" show(D)
 D= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 2 & 0 & 0 \\ 0 & -3 & 0 \\ 0 & 0 & 0 \end{array}\right) D=

### 스칼라행렬 $S$

c = var('c') S = Matrix([[c,0,0],[0,c,0],[0,0,c]]) print "S=" show(S)
 S= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} c & 0 & 0 \\ 0 & c & 0 \\ 0 & 0 & c \end{array}\right) S=

### 단위행렬 $I$

I = identity_matrix(3) print "I=" show(I)
 I= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array}\right) I=

### 임의의 행렬 $A$

A = random_matrix(QQ,3,3) print "A=" show(A)
 A= \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 1 & 1 & 2 \\ -1 & 0 & 0 \\ 0 & 0 & -1 \end{array}\right) A=

### $$AS = SA = cA$$

show(A*S)
 \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} c & c & 2 \, c \\ -c & 0 & 0 \\ 0 & 0 & -c \end{array}\right)

### $$AI = IA = A$$

show(I*A)
 \newcommand{\Bold}{\mathbf{#1}}\left(\begin{array}{rrr} 1 & 1 & 2 \\ -1 & 0 & 0 \\ 0 & 0 & -1 \end{array}\right)