## 2020年4月4日土曜日

### 数学 - Python - 新しい数とその表示ー複素数と複素平面 - 複素平面 - ド・モアブルの公式と複素数のn乗根 - 三角関数(正弦と余弦)、倍角、展開、実部と虚部

1. 余弦の3倍角について。

$\begin{array}{l}\mathrm{cos}3\theta +i\mathrm{sin}3\theta \\ ={\left(\mathrm{cos}\theta +i\mathrm{sin}\theta \right)}^{3}\\ ={\mathrm{cos}}^{3}\theta +3\left({\mathrm{cos}}^{2}\theta \right)\left(i\mathrm{sin}\theta \right)+3\left(\mathrm{cos}\theta \right){\left(i\mathrm{sin}\theta \right)}^{2}+{\left(i\mathrm{sin}\theta \right)}^{3}\\ ={\mathrm{cos}}^{3}\theta +3i{\mathrm{cos}}^{2}\theta \mathrm{sin}\theta -3{\mathrm{sin}}^{2}\theta \mathrm{cos}\theta -i{\mathrm{sin}}^{3}\theta \\ ={\mathrm{cos}}^{3}\theta -3{\mathrm{sin}}^{2}\theta \mathrm{cos}\theta +i\left(3{\mathrm{cos}}^{2}\theta cin\theta -{\mathrm{sin}}^{3}\theta \right)\\ \mathrm{cos}3\theta ={\mathrm{cos}}^{3}\theta -3{\mathrm{sin}}^{2}\theta \mathrm{cos}\theta \end{array}$

正弦の4倍角について。

$\begin{array}{l}\mathrm{sin}4\theta \\ =\mathrm{Im}\left(\mathrm{cos}4\theta +i\mathrm{sin}4\theta \right)\\ =\mathrm{Im}\left({\left(\mathrm{cos}\theta +i\mathrm{sin}\theta \right)}^{4}\right)\\ =4{\mathrm{cos}}^{3}\theta \mathrm{sin}\theta +4{i}^{2}\mathrm{cos}\theta {\mathrm{sin}}^{3}\theta \\ =4{\mathrm{cos}}^{3}\theta \mathrm{sin}\theta -4\mathrm{cos}\theta {\mathrm{sin}}^{3}\theta \end{array}$

余弦の5倍角について。

$\begin{array}{l}\mathrm{Re}\left(\mathrm{cos}5\theta +i\mathrm{sin}5\theta \right)\\ =\mathrm{Re}\left({\left(\mathrm{cos}\theta +i\mathrm{sin}\theta \right)}^{5}\right)\\ ={\mathrm{cos}}^{5}\theta +10{\mathrm{cos}}^{3}\theta {\left(i\mathrm{sin}\theta \right)}^{2}+5\left(\mathrm{cos}\theta \right){\left(i\mathrm{sin}\theta \right)}^{4}\\ ={\mathrm{cos}}^{5}\theta -10{\mathrm{cos}}^{3}\theta {\mathrm{sin}}^{2}\theta +5\mathrm{cos}\theta {\mathrm{sin}}^{4}\theta \end{array}$

コード

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

print('10.')

theta = symbols('θ')

class MyTestCase(TestCase):
def test_cos3(self):
self.assertEqual(
cos(3 * theta),
(cos(theta) ** 3 -
3 * sin(theta) ** 2 * cos(theta)).simplify())

def test_sin4(self):
self.assertEqual(
sin(4 * theta),
(4 * cos(theta) ** 3 * sin(theta) -
4 * cos(theta) * sin(theta) ** 3).simplify())

def test_cos5(self):
for theta in range(-10, 11):
self.assertEqual(
float(cos(5 * theta)),
float(cos(theta) ** 5 - 10 * cos(theta) ** 3 * sin(theta) ** 2 +
5 * cos(theta) * sin(theta) ** 4))

if __name__ == "__main__":
main()


% ./sample10.py -v
10.
test_cos3 (__main__.MyTestCase) ... ok
test_cos5 (__main__.MyTestCase) ... ok
test_sin4 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.439s

OK
%