## 2019年11月8日金曜日

### 数学 - Python - 円の中にひそむ関数 - 三角関数 - 加法定理 - 正弦・余弦の加法定理 - 和、差、象限、符号

1. $\begin{array}{l}\mathrm{sin}\left(\alpha +\beta \right)\\ =\mathrm{sin}\alpha \mathrm{cos}\beta +\mathrm{cos}\alpha \mathrm{sin}\beta \\ =\frac{5}{13}·\left(-\frac{3}{5}\right)+\frac{12}{13}·\left(-\frac{4}{5}\right)\\ =\frac{-15-48}{13·5}\\ =-\frac{63}{65}\\ \mathrm{cos}\left(\alpha +\beta \right)\\ =\mathrm{cos}\alpha \mathrm{cos}\beta -\mathrm{sin}\alpha \mathrm{sin}\beta \\ =\frac{12}{13}·\left(-\frac{3}{5}\right)-\frac{5}{13}·\left(-\frac{4}{5}\right)\\ =\frac{-36+20}{65}\\ =-\frac{16}{65}\\ \mathrm{cos}\left(\alpha -\beta \right)\\ =\mathrm{cos}\alpha \mathrm{cos}\beta +\mathrm{sin}\alpha \mathrm{sin}\beta \\ =\frac{12}{13}·\left(-\frac{3}{5}\right)+\frac{5}{13}·\left(-\frac{4}{5}\right)\\ =\frac{-36-20}{65}\\ =-\frac{56}{65}\end{array}$

コード

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

print('15.')

class MyTestCase(TestCase):

def test(self):
alpha = asin(Rational(5, 13))
beta = -acos(-Rational(3, 5))
spam = [sin(alpha + beta),
cos(alpha + beta),
cos(alpha - beta)]
egg = [-Rational(63, 65),
-Rational(16, 65),
-Rational(56, 65)]
for s, t in zip(spam, egg):
self.assertEqual(float(s), float(t))

if __name__ == '__main__':
main()


% ./sample15.py -v
15.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.026s

OK
%