## 2019年8月30日金曜日

### 数学 - Python - 解析学 - 各種の初等関数 - 三角関数 - 加法定理、正弦、余弦、正接、半角

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

コード

Python 3

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

print('7.')

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

def tearDown(self):
pass

def test(self):
spam = [sin, cos, tan]
egg = [sqrt(2 - sqrt(2)) / 2,
sqrt(2 + sqrt(2)) / 2,
sqrt(2) - 1]
for s, t in zip(spam, egg):
self.assertEqual(s(pi / 8).factor(), t.factor())

if __name__ == '__main__':
theta = symbols('θ')
p = plot(sin(theta), cos(theta), tan(theta),
sqrt(2 - sqrt(2)) / 2,
sqrt(2 + sqrt(2)) / 2,
sqrt(2) - 1,
(theta, -5, 5),
ylim=(-5, 5),
show=False,
legend=True)

colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']

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

p.show()
p.save('sample7.png')
main()


C:\Users\...>py sample7.py
7.
.
----------------------------------------------------------------------
Ran 1 test in 0.021s

OK

C:\Users\...>