2018年1月17日水曜日

学習環境

線型代数入門(松坂 和夫(著)、岩波書店)の第5章(行列式)、6(行列式の計算)、問題6.を取り組んでみる。


    1. det ( 3 1 1 4 3 - 1 5 4 1 ) = det ( 0 0 1 7 4 - 1 2 3 1 ) = 21 - 8 = 13
      x = 1 13 det ( - 5 1 1 - 2 3 - 1 6 4 1 ) = 1 13 det ( 0 0 1 - 7 4 - 1 11 3 1 ) = 1 13 - 21 - 44 = - 65 13 = - 5
      y = 1 13 det ( 3 - 5 1 4 - 2 - 1 5 6 1 ) = 1 13 det ( 0 0 1 7 - 7 - 1 2 11 1 ) = 1 13 77 + 14 = 91 13 = 7
      z = 1 13 det ( 3 1 - 5 4 3 - 2 5 4 6 ) = 1 13 det ( 0 1 0 - 5 3 13 - 7 4 26 ) = 1 13 130 - 91 = 10 - 7 = 3

    2. det ( 1 2 - 1 - 1 1 - 1 1 1 1 - 1 - 1 0 1 0 0 1 ) = det ( 2 2 - 1 0 0 - 1 1 0 1 - 1 - 1 0 0 0 0 1 ) = 2 + 2 - - 2 + 1 = 5
      x = 1 5 det ( 3 2 - 1 - 1 3 - 1 1 1 4 - 1 - 1 0 4 0 0 1 ) = 1 5 det ( 6 1 0 0 3 - 1 1 1 4 - 1 - 1 0 4 0 0 1 ) = 1 5 det ( 6 1 0 0 - 1 - 1 1 0 4 - 1 - 1 0 4 0 0 1 ) = 1 5 6 + 4 - - 6 + 1 = 3
      y = 1 5 det ( 1 3 - 1 - 1 1 3 1 1 1 4 - 1 0 1 4 0 1 ) = 1 5 det ( 2 7 - 1 0 0 - 1 1 0 1 4 - 1 0 1 4 0 1 ) = 1 5 2 + 7 - 8 + 1 = 0
      z = 1 5 det ( 1 2 3 - 1 1 - 1 3 1 1 - 1 4 0 1 0 4 1 ) = 1 5 det ( 2 2 7 0 0 - 1 - 1 0 1 - 1 4 0 1 0 4 1 ) = 1 5 - 8 - 2 - 2 - 7 = - 1
      w = 1 5 det ( 1 2 - 1 3 1 - 1 1 3 1 - 1 - 1 4 1 0 0 4 ) = 1 5 det ( 1 2 1 - 1 1 - 1 0 - 1 1 - 1 - 2 0 1 0 0 0 ) = - 1 5 1 - 2 - 4 = 1

コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, Matrix, solve

x, y, z, w = symbols('x, y, z, w')
exprs = [
    (
        3 * x + y + z + 5,
        4 * x + 3 * y - z + 2,
        5 * x + 4 * y + z - 6
    ),
    (
        x + 2 * y - z - w - 3,
        x - y + z + w - 3,
        x - y - z - 4,
        x + w - 4
    )
]

for i, expr in enumerate(exprs):
    print(f'({chr(ord("a") + i)})')
    for t in [expr, solve(expr)]:
        pprint(t)
        print()
    print()

入出力結果(Terminal, Jupyter(IPython))

$ ./sample6.py
(a)
(3⋅x + y + z + 5, 4⋅x + 3⋅y - z + 2, 5⋅x + 4⋅y + z - 6)

{x: -5, y: 7, z: 3}


(b)
(-w + x + 2⋅y - z - 3, w + x - y + z - 3, x - y - z - 4, w + x - 4)

{w: 1, x: 3, y: 0, z: -1}


$

0 コメント:

コメントを投稿

関連コンテンツ