## 2019年12月17日火曜日

### 数学 - Python - 円の中にひそむ関数 - 三角関数 - 三角関数と三角形 - 余弦定理 - 辺の長さ、角、三角関数表

1. $\begin{array}{l}{a}^{2}\\ ={b}^{2}+{c}^{2}-2bc\mathrm{cos}A\\ ={4}^{2}+{6}^{2}-2·4·6\mathrm{cos}\frac{2}{3}\pi \\ =16+36-48·\left(-\frac{1}{2}\right)\\ =52+24\\ =76\\ a=\sqrt{76}\\ =2\sqrt{19}\end{array}$

2. $\begin{array}{l}{a}^{2}\\ =1{0}^{2}+{7}^{2}-2·10·7\mathrm{cos}4{0}^{\circ }\\ \fallingdotseq 100+49-140·0.7660\\ =149-107.24\\ =41.76\\ a\fallingdotseq 6.46\end{array}$

3. $\begin{array}{l}{c}^{2}={a}^{2}+{b}^{2}-2ab\mathrm{cos}C\\ 63=27+{b}^{2}-2·3\sqrt{3}b\mathrm{cos}\frac{5}{6}\pi \\ {b}^{2}+9b-36=0\\ b=\frac{-9+\sqrt{81+144}}{2}\\ =\frac{-9+\sqrt{225}}{2}\\ =\frac{-9+15}{2}\\ =3\end{array}$

4. $\begin{array}{l}49=25+64-80\mathrm{cos}A\\ \mathrm{cos}A=\frac{1}{2}\\ A=\frac{\pi }{3}\end{array}$

5. $\begin{array}{l}64=49+25-70\mathrm{cos}C\\ \mathrm{cos}C\\ =\frac{1}{7}\\ \fallingdotseq 0.1428\\ C\fallingdotseq 8{2}^{\circ }\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, cos, sqrt, solve, pi, rad
print('40.')

a, b, A, C = symbols('a, b, A, C', real=True, positive=True)

class MyTestCase(TestCase):
def test1(self):
s = solve(a ** 2 - (4 ** 2 + 6 ** 2 - 2 * 4 * 6 * cos(2 * pi / 3)))[0]
self.assertEqual(s, 2 * sqrt(19))

def test2(self):
s = solve(a ** 2 - (10 ** 2 + 7 ** 2 - 2 * 10 * 7 * cos(rad(40))))[0]
self.assertAlmostEqual(float(s), 6.46, places=2)

def test3(self):
s = solve((3 * sqrt(7)) ** 2 - ((3 * sqrt(3)) ** 2 + b **
2 - 2 * 3 * sqrt(3) * b * cos(5 * pi / 6)))[0]
self.assertEqual(s, 3)

def test4(self):
s = solve(7 ** 2 - (5 ** 2 + 8 ** 2 - 2 * 5 * 8 * cos(A)))[0]
self.assertEqual(s, pi / 3)

def test5(self):
s = solve(8 ** 2 - (7 ** 2 + 5 ** 2 - 2 * 7 * 5 * cos(C)))[1]

if __name__ == '__main__':
main()


% ./sample40.py -v
40.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok
test3 (__main__.MyTestCase) ... ok
test4 (__main__.MyTestCase) ... ok
test5 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 5 tests in 0.517s

OK
%