学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
ラング線形代数学(上) (ちくま学現文庫)(S.ラング (著)、芹沢 正三 (翻訳)、筑摩書房)の1章(R^nにおけるベクトル)、6(複素数)、練習問題6の解答を求めてみる。
よって、
ならば
また、
ならば、
となる l が存在するから
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Matrix, I
print('6')
n = 2
A = Matrix([symbols([f'a{i}' for i in range(1, n + 1)], imag=True)])
B = Matrix([symbols([f'b{i}' for i in range(1, n + 1)], imag=True)])
C = Matrix([symbols([f'c{i}' for i in range(1, n + 1)], imag=True)])
alpha = symbols('α', imag=True)
def dot(a, b):
return sum([a0 * b0.conjugate() for a0, b0 in zip(a, b)])
class MyTestCase(TestCase):
def test_sp1(self):
self.assertEqual(dot(A, B), dot(B, A).conjugate())
def test_sp2(self):
self.assertEqual(dot(A, B + C).expand(),
(dot(A, B) + dot(A, C)).expand())
def test_sp3_1(self):
self.assertEqual(dot(alpha * A, B).expand(),
(alpha * dot(A, B)).expand())
def test_sp3_2(self):
self.assertEqual(dot(A, alpha * B).expand(),
(alpha.conjugate() * dot(A, B)).expand())
def test_sp4_1(self):
O = Matrix([0 for _ in range(n)])
self.assertEqual(dot(O, O), 0)
def test_sp4_2(self):
A = Matrix([1, 0, 0, 0, 0])
B = Matrix([I, 0, 0, 0, 0])
C = Matrix([1 - I, 0, 0, 0, 0])
for t in [A, B, C]:
self.assertGreater(dot(A, A), 0)
if __name__ == '__main__':
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample6.py -v
6
test_sp1 (__main__.MyTestCase) ... ok
test_sp2 (__main__.MyTestCase) ... ok
test_sp3_1 (__main__.MyTestCase) ... ok
test_sp3_2 (__main__.MyTestCase) ... ok
test_sp4_1 (__main__.MyTestCase) ... ok
test_sp4_2 (__main__.MyTestCase) ... ok
----------------------------------------------------------------------
Ran 6 tests in 0.058s
OK
%
0 コメント:
コメントを投稿