## 2019年12月15日日曜日

### 数学 - Python - 線形代数学 - R^nにおけるベクトル - 複素数 - 積、逆数、除算、共役

ラング線形代数学(上) (ちくま学現文庫)(S.ラング (著)、芹沢 正三 (翻訳)、筑摩書房)の1章(R^nにおけるベクトル)、6(複素数)、練習問題1の解答を求めてみる。

1. $\begin{array}{l}\frac{1}{-1+3i}\\ =-\frac{1}{10}-\frac{3}{10}i\end{array}$

2. $\begin{array}{l}\left(1+i\right)\left(1-i\right)\\ =2\end{array}$

3. $\begin{array}{l}\left(1+i\right)i\left(2-i\right)\\ =\left(-1+i\right)\left(2-i\right)\\ =-1+3i\end{array}$

4. $\begin{array}{l}\left(i-1\right)\left(2-i\right)\\ =-1+3i\end{array}$

5. $\begin{array}{l}\left(7+\pi i\right)\left(\pi +i\right)\\ =6\pi +\left(7+{\pi }^{2}\right)i\end{array}$

6. $\begin{array}{l}\left(2i+1\right)\pi i\\ =-2\pi +\pi i\end{array}$

7. $\begin{array}{l}\left(\sqrt{2}+i\right)\left(\pi +3i\right)\\ =\left(\sqrt{2}\pi -3\right)+\left(\pi +3\sqrt{2}\right)i\end{array}$

8. $\begin{array}{l}\left(i+1\right)\left(i-2\right)\left(i+3\right)\\ =\left(-3-i\right)\left(i+3\right)\\ =-{\left(i+3\right)}^{2}\\ =-8-6i\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, pi, I, sqrt, Rational

print('1.')

class MyTestCase(TestCase):
def test(self):
spam = [(-1 + 3 * I) ** -1,
(1 + I) * (1 - I),
(1 + I) * I * (2 - I),
(I - 1) * (2 - I),
(7 + pi * I) * (pi + I),
(2 * I + 1) * pi * I,
(sqrt(2) + I) * (pi + 3 * I),
(I + 1) * (I - 2) * (I + 3)]
egg = [-Rational(1, 10) - Rational(3, 10) * I,
2 + 0 * I,
-1 + 3 * I,
-1 + 3 * I,
6 * pi + (7 + pi ** 2) * I,
-2 * pi + pi * I,
(sqrt(2) * pi - 3) + (pi + 3 * sqrt(2)) * I,
-8 - 6 * I]
for s, t in zip(spam, egg):
self.assertEqual(s.expand(), t.expand())

if __name__ == '__main__':
main()


% ./sample1.py -v
1.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.015s

OK
%