2019年8月29日木曜日

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

1. $\begin{array}{l}\mathrm{sin}\frac{\pi }{12}\\ =\mathrm{sin}\left(\frac{\pi }{3}-\frac{\pi }{4}\right)\\ =\mathrm{sin}\frac{\pi }{3}\mathrm{cos}\frac{\pi }{4}-\mathrm{cos}\frac{\pi }{3}\mathrm{sin}\frac{\pi }{4}\\ =\frac{\sqrt{3}}{2}·\frac{1}{\sqrt{2}}-\frac{1}{2}·\frac{1}{\sqrt{2}}\\ =\frac{\sqrt{3}-1}{2\sqrt{2}}\\ =\frac{\sqrt{6}-\sqrt{2}}{4}\\ \mathrm{cos}\frac{\pi }{12}\\ =\mathrm{cos}\left(\frac{\pi }{3}-\frac{\pi }{4}\right)\\ =\mathrm{cos}\frac{\pi }{3}\mathrm{cos}\frac{\pi }{4}+\mathrm{sin}\frac{\pi }{3}\mathrm{sin}\frac{\pi }{4}\\ =\frac{1}{2}·\frac{1}{\sqrt{2}}+\frac{\sqrt{3}}{2}·\frac{1}{\sqrt{2}}\\ =\frac{1+\sqrt{3}}{2\sqrt{2}}\\ =\frac{\sqrt{2}+\sqrt{6}}{4}\\ \mathrm{tan}\frac{\pi }{12}\\ =\mathrm{tan}\left(\frac{\pi }{3}-\frac{\pi }{4}\right)\\ =\frac{\mathrm{tan}\frac{\pi }{3}-\mathrm{tan}\frac{\pi }{4}}{1+\mathrm{tan}\frac{\pi }{3}\mathrm{tan}\frac{\pi }{4}}\\ =\frac{\sqrt{3}-1}{1+\sqrt{3}·1}\\ =\frac{3-2\sqrt{3}+1}{3-1}\\ =\frac{4-2\sqrt{3}}{2}\\ =2-\sqrt{3}\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('6.')

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

def tearDown(self):
pass

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

if __name__ == '__main__':
theta = symbols('θ')
p = plot(sin(theta), cos(theta), tan(theta),
(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('sample6.png')
main()


C:\Users\...>py sample6.py
6.
.
----------------------------------------------------------------------
Ran 1 test in 0.024s

OK

C:\Users\...>