7.1 행렬, 벡터: 합과 스칼라곱

예제 1미지수 $x$, $y$, $z$를 가진 다음의 선형연립방정식이 주어졌다고 생각하자.

x, y, z = var('x,y,z') eq1 = 4*x + 6*y + 9*z == 6 eq2 = 6*x + - 2*z == 20 eq3 = 5*x - 8*y + z == 10 show(eq1) show(eq2) show(eq3)
 \newcommand{\Bold}[1]{\mathbf{#1}}4 \, x + 6 \, y + 9 \, z = 6 \newcommand{\Bold}[1]{\mathbf{#1}}6 \, x - 2 \, z = 20 \newcommand{\Bold}[1]{\mathbf{#1}}5 \, x - 8 \, y + z = 10

계수행렬 $A$와 우변벡터 $\bf{b}$

A=matrix([[4,6,9],[6,0,-2],[5,-8,1]]) b=matrix(3,1,[6,20,10]) print "A = " show(A) print "b = " show(b)
 A = \newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrr} 4 & 6 & 9 \\ 6 & 0 & -2 \\ 5 & -8 & 1 \end{array}\right) b = \newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{r} 6 \\ 20 \\ 10 \end{array}\right) A = b = 

첨가행렬 $\tilde{A} = [A:\bf{b}]$

Ab=A.augment(b) #첨가행렬 만들기 print "[A:b] = " show(Ab)
 [A:b] = \newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrrr} 4 & 6 & 9 & 6 \\ 6 & 0 & -2 & 20 \\ 5 & -8 & 1 & 10 \end{array}\right) [A:b] =

행렬 $A$와 $B$

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

행렬의 합 $A+B$

print "A+B = " show(A+B) #행렬의 합
 A+B = \newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrr} 1 & 5 & 3 \\ 3 & 2 & 2 \end{array}\right) A+B =

벡터 $\bf{a}$ 와 $\bf{b}$

a = vector([5, 7, 2]) b = vector([-6, 2, 0]) print "a = " show(a) print "b=" show(b)
 a = \newcommand{\Bold}[1]{\mathbf{#1}}\left(5,\,7,\,2\right) b= \newcommand{\Bold}[1]{\mathbf{#1}}\left(-6,\,2,\,0\right) a = b=

벡터의 합 $\bf{a}+\bf{b}$

print "a+b = " show(a+b) #벡터의 합
 a+b = \newcommand{\Bold}[1]{\mathbf{#1}}\left(-1,\,9,\,2\right) a+b =

행렬 $A$

A = matrix(RDF,[[2.7,-1.8],[0,0.9],[9.0,-4.5]]) print "A=" show(A)
 A= \newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr} 2.7 & -1.8 \\ 0.0 & 0.9 \\ 9.0 & -4.5 \end{array}\right) A=

스칼라곱 $(-1)A = -A$

print "-A = " show(-1*A) #스칼라 곱
 -A = \newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr} -2.7 & 1.8 \\ -0.0 & -0.9 \\ -9.0 & 4.5 \end{array}\right) -A =

스칼라곱 $\frac{10}{9}A$

print "(10/9)*A = " show((10/9)*A) #스칼라 곱
 (10/9)*A = \newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr} 3.0 & -2.0 \\ 0.0 & 1.0 \\ 10.0 & -5.0 \end{array}\right) (10/9)*A =

행렬 $0A$

print "0*A = " show(0*A) #스칼라 곱
 0*A = \newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rr} 0.0 & -0.0 \\ 0.0 & 0.0 \\ 0.0 & -0.0 \end{array}\right) 0*A =