## 2020年3月23日月曜日

### 数学 - Python - 新しい数とその表示ー複素数と複素平面 - 複素平面 - 複素の絶対値 - 積の絶対値と絶対値の積、商の絶対値と絶対値の商

1. $\begin{array}{l}\left|-2i\left(3+i\right)\left(2-4i\right)\left(1+i\right)\right|\\ =\left|-2i\right|\left|3+i\right|\left|2-4i\right|\left|1+i\right|\\ =2·\sqrt{9+1}\sqrt{4+16}\sqrt{1+1}\\ =2\sqrt{2·5}\sqrt{{2}^{2}·5}\sqrt{2}\\ =40\end{array}$

2. $\begin{array}{l}\left|\frac{\left(-1+2i\right)\left(3-2i\right)}{\left(1+i\right)\left(3-4i\right)}\right|\\ =\frac{\sqrt{1+4}\sqrt{9+4}}{\sqrt{2}\sqrt{25}}\\ =\frac{\sqrt{5}\sqrt{13}}{5\sqrt{2}}\\ =\frac{\sqrt{130}}{10}\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, I, sqrt
print('2.')

class MyTestCase(TestCase):
def test1(self):
self.assertEqual(abs(-2 * I * (3 + I) * (2 - 4 * I) * (1 + I)), 40)

def test2(self):
self.assertEqual(abs(((-1 + 2 * I) * (3 - 2 * I)) /
((1 + I) * (3 - 4 * I))),
sqrt(130) / 10)

if __name__ == "__main__":
main()


% ./sample2.py -v
2.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.079s

OK
%