## 2019年12月7日土曜日

### 数学 - Python - 円の中にひそむ関数 - 三角関数 - 加法定理 - 三角関数の諸公式 - 正弦と余弦、積を和または差に変形して計算

1. $\begin{array}{l}\mathrm{sin}7{5}^{\circ }\mathrm{cos}1{5}^{\circ }\\ =\frac{1}{2}\left(\mathrm{sin}\left(7{5}^{\circ }+1{5}^{\circ }\right)+\mathrm{sin}\left(7{5}^{\circ }-1{5}^{\circ }\right)\right)\\ =\frac{1}{2}\left(\mathrm{sin}\frac{\pi }{2}+\mathrm{sin}\frac{\pi }{3}\right)\\ =\frac{1}{2}\left(1+\frac{\sqrt{3}}{2}\right)\\ =\frac{1}{2}·\frac{2+\sqrt{3}}{2}\\ =\frac{2+\sqrt{3}}{4}\end{array}$

2. $\begin{array}{l}\mathrm{cos}22.{5}^{\circ }\mathrm{cos}67.{5}^{\circ }\\ =\frac{\mathrm{cos}\left(22.{5}^{\circ }+67.{5}^{\circ }\right)+\mathrm{cos}\left(67.{5}^{\circ }-22.{5}^{\circ }\right)}{2}\\ =\frac{1}{2}\left(\mathrm{cos}\frac{\pi }{2}+\mathrm{cos}\frac{\pi }{4}\right)\\ =\frac{1}{2}\left(0+\frac{1}{\sqrt{2}}\right)\\ =\frac{1}{2\sqrt{2}}\end{array}$

3. $\begin{array}{l}\mathrm{sin}52.{5}^{\circ }\mathrm{sin}7.{5}^{\circ }\\ =\frac{1}{2}\left(\mathrm{cos}\left(52.{5}^{\circ }-7.{5}^{\circ }\right)-\mathrm{cos}\left(52.{5}^{\circ ·}+7.{5}^{\circ }\right)\right)\\ =\frac{1}{2}\left(\mathrm{cos}\frac{\pi }{4}-\mathrm{cos}\frac{\pi }{3}\right)\\ =\frac{1}{2}\left(\frac{1}{\sqrt{2}}-\frac{1}{2}\right)\\ =\frac{1}{2}·\frac{2-\sqrt{2}}{2\sqrt{2}}\\ =\frac{1}{2}\frac{2\sqrt{2}-2}{4}\\ =\frac{\sqrt{2}-1}{4}\end{array}$

4. $\begin{array}{l}\mathrm{cos}4{0}^{\circ }\mathrm{cos}2{0}^{\circ }-\mathrm{cos}7{0}^{\circ }\mathrm{cos}5{0}^{\circ }\\ =\frac{1}{2}\left(\mathrm{cos}\left(4{0}^{\circ }+2{0}^{\circ }\right)+\mathrm{cos}\left(4{0}^{\circ }-2{0}^{\circ }\right)-\left(\mathrm{cos}\left(7{0}^{\circ }+5{0}^{\circ }\right)+\mathrm{cos}\left(7{0}^{\circ }-5{0}^{\circ }\right)\right)\right)\\ =\frac{1}{2}\left(\mathrm{cos}6{0}^{\circ }+\mathrm{cos}20·-\mathrm{cos}12{0}^{\circ }-\mathrm{cos}2{0}^{\circ }\right)\\ =\frac{1}{2}\left(\frac{1}{2}-\frac{1}{2}\right)\\ =0\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, sin, cos, Rational, rad, sqrt

print('35.')

class MyTestCase(TestCase):
def test(self):
egg = [(2 + sqrt(3)) / 4,
1 / (2 * sqrt(2)),
(sqrt(2) - 1) / 4,
Rational(1, 2)]
for s, t in zip(exprs, egg):
self.assertAlmostEqual(float(s), float(t))

if __name__ == '__main__':
main()


% ./sample35.py -v
35.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.047s

OK
%