学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
ラング線形代数学(上) (ちくま学現文庫)(S.ラング (著)、芹沢 正三 (翻訳)、筑摩書房)の6章(行列式)、9(行列の逆転)、練習問題1の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Matrix, Rational
print('1.')
class TestInverse(TestCase):
def test(self):
As = [Matrix(t) for t in [
[[2, 1, 2],
[0, 3, -1],
[4, 1, 1]],
[[3, -1, 5],
[-1, 2, 1],
[-2, 4, 3]],
[[2, 4, 3],
[-1, 3, 0],
[0, 2, 1]],
[[1, 2, -1],
[0, 1, 1],
[0, 2, 7]],
[[-1, 5, 3],
[4, 0, 0],
[2, 7, 8]]
]]
Bs = [c * Matrix(t) for c, t in [
(-Rational(1, 20),
[[4, 1, -7],
[-4, -6, 2],
[-12, 2, 6]]),
(Rational(1, 5),
[[2, 23, -11],
[1, 19, -8],
[0, -10, 5]]),
(Rational(1, 4),
[[3, 2, -9],
[1, 2, -3],
[-2, -4, 10]]),
(Rational(1, 5),
[[5, -16, 3],
[0, 7, -1],
[0, -2, 1]]),
(-Rational(1, 76),
[[0, -19, 0],
[-32, -14, 12],
[28, 17, -20]])
]]
for i, (A, B) in enumerate(zip(As, Bs)):
print(f'({chr(ord("a") + i)})')
self.assertEqual(A.inv(), B)
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample1.py -v
1.
test (__main__.TestInverse) ... (a)
(b)
(c)
(d)
(e)
ok
----------------------------------------------------------------------
Ran 1 test in 0.008s
OK
%
0 コメント:
コメントを投稿