## 2019年11月26日火曜日

### 数学 - Python - 円の中にひそむ関数 - 三角関数 - 加法定理 - 三角関数の諸公式の正接 - 正弦と余弦と正接、等式の証明、累乗(平方)、2倍角、半角

1. $\begin{array}{l}{\left(\mathrm{cos}\alpha +\mathrm{sin}\alpha \right)}^{2}\\ ={\mathrm{cos}}^{2}\alpha +2\mathrm{sin}\alpha \mathrm{cos}\alpha +{\mathrm{sin}}^{2}\alpha \\ =1+\mathrm{sin}\left(2\alpha \right)\end{array}$

2. $\begin{array}{l}{\mathrm{cos}}^{4}\alpha -{\mathrm{sin}}^{4}\alpha \\ =\left({\mathrm{cos}}^{2}\alpha +{\mathrm{sin}}^{2}\alpha \right)\left({\mathrm{cos}}^{2}\alpha -{\mathrm{sin}}^{2}\alpha \right)\\ =\mathrm{cos}\left(\alpha -\alpha \right)\mathrm{cos}\left(\alpha +\alpha \right)\\ =\mathrm{cos}\left(2\alpha \right)\end{array}$

3. $\begin{array}{l}\mathrm{tan}\frac{\alpha }{2}\\ =\frac{\mathrm{sin}\frac{\alpha }{2}}{\mathrm{cos}\frac{\alpha }{2}}\\ =\frac{2\mathrm{sin}\frac{\alpha }{2}\mathrm{cos}\frac{\alpha }{2}}{2{\mathrm{cos}}^{2}\frac{\alpha }{2}}\\ =\frac{\mathrm{sin}\alpha }{\mathrm{cos}\left(\frac{\alpha }{2}+\frac{\alpha }{2}\right)+\mathrm{cos}\left(\frac{\alpha }{2}-\frac{\alpha }{2}\right)}\\ =\frac{\mathrm{sin}\alpha }{1+\mathrm{cos}\alpha }\\ \mathrm{tan}\frac{\alpha }{2}\\ =\frac{\mathrm{sin}\frac{\alpha }{2}}{\mathrm{cos}\frac{\alpha }{2}}\\ =\frac{2{\mathrm{sin}}^{2}\frac{\alpha }{2}}{2\mathrm{cos}\frac{\alpha }{2}\mathrm{sin}\frac{\alpha }{2}}\\ =\frac{\mathrm{cos}\left(\frac{\alpha }{2}-\frac{\alpha }{2}\right)-\mathrm{cos}\left(\frac{\alpha }{2}+\frac{\alpha }{2}\right)}{\mathrm{sin}\alpha }\\ =\frac{1-\mathrm{cos}\alpha }{\mathrm{sin}\alpha }\end{array}$

4. $\begin{array}{l}\frac{\mathrm{sin}\alpha }{1+\mathrm{cos}\alpha }+\frac{1+\mathrm{cos}\alpha }{\mathrm{sin}\alpha }\\ =\frac{{\mathrm{sin}}^{2}\alpha +1+2\mathrm{cos}\alpha +{\mathrm{cos}}^{2}\alpha }{\left(1+\mathrm{cos}\alpha \right)\mathrm{sin}\alpha }\\ =\frac{2\left(1+\mathrm{cos}\alpha \right)}{\left(1+\mathrm{cos}\alpha \right)\mathrm{sin}\alpha }\\ =\frac{2}{\mathrm{sin}\alpha }\end{array}$

（証明終）

コード

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

print('27.')

x = symbols('x')

class MyTestCase(TestCase):
def test(self):
alpha = 1
spam = [((cos(alpha) + sin(alpha)) ** 2, 1 + sin(2 * alpha)),
(cos(alpha) ** 4 - sin(alpha) ** 4, cos(2 * alpha)),
(sin(alpha) / (1 + cos(alpha)),
(1 - cos(alpha)) / sin(alpha), tan(alpha / 2)),
((sin(alpha) / (1 + cos(alpha))) + (1 + cos(alpha)) / sin(alpha), 2 / sin(alpha))]
for s in spam:
self.assertEqual(*[float(t) for t in s])

p = plot(1 + sin(2 * x),
cos(2 * x),
tan(x / 2),
2 / sin(x),
ylim=(-10, 10),
legend=True,
show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']

for s, color in zip(p, colors):
s.line_color = color

p.show()
p.save(f'sample27.png')

if __name__ == '__main__':
main()


% ./sample27.py -v
27.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.007s

OK
%