## 2020年4月6日月曜日

### 数学 - Python - 新しい数とその表示ー複素数と複素平面 - 複素平面 - ド・モアブルの公式と複素数のn乗根 - 平方根、3乗根、4乗根、5乗根、絶対値、偏角

1. $\begin{array}{l}1+i\\ =\sqrt{2}\left(\mathrm{cos}\left(\frac{\pi }{4}+2k\pi \right)+i\mathrm{sin}\left(\frac{\pi }{4}+2k\pi \right)\right)\end{array}$

よって 問題の複素数の平方根の極形式は

$\begin{array}{l}{\left(1+i\right)}^{\frac{1}{2}}\\ =\sqrt[4]{2}\left(\mathrm{cos}\left(\frac{\pi }{8}+k\pi \right)+i\mathrm{sin}\left(\frac{\pi }{8}+k\pi \right)\right)\end{array}$

2. $\begin{array}{l}{i}^{\frac{1}{3}}\\ ={\left(\mathrm{cos}\left(\frac{\pi }{2}+2k\pi \right)+i\mathrm{sin}\left(\frac{\pi }{2}+2k\pi \right)\right)}^{\frac{1}{3}}\\ =\mathrm{cos}\left(\frac{\pi }{6}+\frac{2}{3}k\pi \right)+i\mathrm{sin}\left(\frac{\pi }{6}+\frac{2}{3}k\pi \right)\end{array}$

3. $\begin{array}{l}-2+2\sqrt{3}i\\ =4\left(-\frac{1}{2}+\frac{\sqrt{3}i}{2}\right)\\ =4\left(\mathrm{cos}\left(\frac{2\pi }{3}+2k\pi \right)+i\mathrm{sin}\left(\frac{2\pi }{3}+2k\pi \right)\right)\\ {\left(-2+2\sqrt{3}i\right)}^{\frac{1}{4}}\\ =\sqrt{2}\left(\mathrm{cos}\left(\frac{\pi }{6}+\frac{k}{2}\pi \right)+i\mathrm{sin}\left(\frac{\pi }{6}+\frac{k}{2}\pi \right)\right)\end{array}$

4. $\begin{array}{l}-1\\ =\mathrm{cos}\left(\pi +2k\pi \right)+i\mathrm{sin}\left(\pi +2k\pi \right)\\ {\left(-1\right)}^{\frac{1}{5}}\\ =\mathrm{cos}\left(\frac{\pi }{5}+\frac{2}{5}k\pi \right)+i\mathrm{sin}\left(\frac{\pi }{5}+\frac{2}{5}k\pi \right)\end{array}$

コード

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

print('12.')

zs = [1 + I,
I,
-2 + 2 * sqrt(3) * I,
-1]
ns = [2, 3, 4, 5]
k = symbols('k', integer=True)
ras = [(root(2, 4), pi / 8 + k * pi),
(1, pi / 6 + 2 * k * pi / 3),
(sqrt(2), pi / 6 + k * pi / 2),
(1, pi / 5 + 2 * k * pi / 5)]

class MyTestCase(TestCase):
def test(self):
for i, (z, n, (r, a)) in enumerate(zip(zs, ns, ras), 1):
print(f'({i})')
if type(z) == int:
c = z
d = 0
else:
c, d = z.as_real_imag()
for k0 in range(n):
e, f = ((r * (cos(a) + I * sin(a))) **
n).subs({k: k0}).as_real_imag()
self.assertAlmostEqual(float(c), float(e))
self.assertAlmostEqual(float(d), float(f))

if __name__ == "__main__":
main()


% ./sample12.py -v
12.
test (__main__.MyTestCase) ... (1)
(2)
(3)
(4)
ok

----------------------------------------------------------------------
Ran 1 test in 0.272s

OK
%