学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
ラング線形代数学(上) (ちくま学現文庫)(S.ラング (著)、芹沢 正三 (翻訳)、筑摩書房)の3章(行列)、2(行列の積)、練習問題20の解答を求めてみる。
学習環境
ラング線形代数学(上) (ちくま学現文庫)(S.ラング (著)、芹沢 正三 (翻訳)、筑摩書房)の3章(行列)、2(行列の積)、練習問題20の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix
print('20.')
a = Matrix([[1, 2],
[3, -1]])
b = Matrix([[2, 0],
[1, 1]])
class MyTestCase(TestCase):
def testA(self):
self.assertEqual(a.trace(), 0)
def testB(self):
self.assertEqual(b.trace(), 3)
def testAB(self):
self.assertEqual((a * b).trace(), 3)
def testBA(self):
self.assertEqual((b * a).trace(), 3)
if __name__ == '__main__':
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample20.py -v
20.
testA (__main__.MyTestCase) ... ok
testAB (__main__.MyTestCase) ... ok
testB (__main__.MyTestCase) ... ok
testBA (__main__.MyTestCase) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.041s
OK
%
0 コメント:
コメントを投稿