## 2019年10月7日月曜日

### 数学 - Python - 解析学 - 各種の初等関数 - 複素数の幾何学的表現 - ド・モアブルの公式、倍角、三角関数(正弦と余弦)

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

よって、

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

コード

Python 3

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

print('4.')

class MyTest(TestCase):
def setUp(self):
pass

def tearDown(self):
pass

def test(self):
theta = symbols('θ')
spam = [f(o) for o in [4 * theta, 5 * theta] for f in [cos, sin]]
egg = [cos(theta) ** 4 - 6 * cos(theta) ** 2 *
sin(theta) ** 2 + sin(theta) ** 4,
4 * cos(theta) ** 3 * sin(theta) -
4 * cos(theta) * sin(theta) ** 3,
cos(theta) ** 5 - 10 * cos(theta) ** 3 * sin(theta) ** 2 +
5 * cos(theta) * sin(theta) ** 4,
5 * cos(theta) ** 4 * sin(theta) -
10 * cos(theta) ** 2 * sin(theta) ** 3 +
sin(theta) ** 5]
for s, t in zip(spam, egg):
for theta0 in range(10):
d = {theta: theta0}
self.assertEqual(float(s.subs(d)), float(t.subs(d)))

if __name__ == '__main__':
main()


$./sample4.py 4. . ---------------------------------------------------------------------- Ran 1 test in 0.093s OK$