2020年2月9日日曜日

学習環境

ラング線形代数学(上) (ちくま学現文庫)(S.ラング (著)、芹沢 正三 (翻訳)、筑摩書房)の3章(行列)、2(行列の積)、練習問題6の解答を求めてみる。



    • C A = [ 7 0 0 7 ] [ 1 2 3 - 1 ] = [ 7 14 21 - 7 ] = 7 [ 1 2 3 - 1 ] = 7 A

    • A C = [ 1 2 3 - 1 ] [ 7 0 0 7 ] = [ 7 14 21 - 7 ] = 7 [ 1 2 3 - 1 ] = 7 A

    • C B = [ 7 0 0 7 ] [ 2 0 1 1 ] = [ 14 0 7 7 ] = 7 [ 2 0 1 1 ] = 7 B

    • B C = [ 2 0 1 1 ] [ 7 0 0 7 ] = [ 14 0 7 7 ] = 7 [ 2 0 1 1 ] = 7 B

      一般的な法則は、

      a K = [ a 0 0 a ] A = A [ a 0 0 a ] = a A

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix

print('6.')

a = Matrix([[1, 2],
            [3, -1]])
b = Matrix([[2, 0],
            [1, 1]])
c = Matrix([[7, 0],
            [0, 7]])


class MyTestCase(TestCase):
    def test_ca(self):
        self.assertEqual(c * a, 7 * a)

    def test_ac(self):
        self.assertEqual(a * c, 7 * a)

    def test_cb(self):
        self.assertEqual(c * b, 7 * b)

    def test_bc(self):
        self.assertEqual(b * c, 7 * b)


if __name__ == '__main__':
    main()

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

% ./sample6.py -v
6.
test_ac (__main__.MyTestCase) ... ok
test_bc (__main__.MyTestCase) ... ok
test_ca (__main__.MyTestCase) ... ok
test_cb (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.001s

OK
%

0 コメント:

コメントを投稿