2020年1月23日木曜日

学習環境

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


  1. A + B T = [ 0 0 2 - 1 ] T = [ 0 2 0 - 1 ] A T + B T = [ 1 2 - 1 2 ] + [ - 1 0 1 - 3 ] = [ 0 2 0 - 1 ]

コード

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

print('8.')

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


class MyTestCase(TestCase):
    def test1(self):
        self.assertEqual((a + b).T,
                         Matrix([[0, 2], [0, -1]]))

    def test2(self):
        self.assertEqual(a.T + b.T,
                         Matrix([[0, 2],
                                 [0, -1]]))


if __name__ == '__main__':
    main()

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

% ./sample8.py -v
8.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.001s

OK
%

0 コメント:

コメントを投稿