## 2019年11月10日日曜日

### 数学 - Python - 円の中にひそむ関数 - 三角関数 - 加法定理 - 正弦・余弦の加法定理 - 等式の証明

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

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

コード

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

print('17.')

alpha = 2
beta = 3

class MyTestCase(TestCase):

def test1(self):
a = sin(alpha + beta) * sin(alpha - beta)
bs = [sin(alpha) ** 2 - sin(beta) ** 2,
cos(beta) ** 2 - cos(alpha) ** 2]
for b in bs:
self.assertEqual(float(a), float(b))

def test2(self):
a = cos(alpha + beta) * cos(alpha - beta)
bs = [cos(alpha) ** 2 - sin(beta) ** 2,
cos(beta) ** 2 - sin(alpha) ** 2]
for b in bs:
self.assertEqual(float(a), float(b))

if __name__ == '__main__':
main()


% ./sample17.py -v
17.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.008s

OK
%