学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windowsアプリ)
- iPad
- MyScript Nebo - MyScript(iPadアプリ(iOS))
- 参考書籍
新装版 数学読本2 (松坂 和夫(著)、岩波書店)の第8章(円の中にひそむ関数 - 三角関数)、8.3(三角関数と三角形)、余弦定理の問40の解答を求めてみる。
コード
#!/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]
self.assertAlmostEqual(float(s), float(rad(82)), places=2)
if __name__ == '__main__':
main()
入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
% ./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
%
0 コメント:
コメントを投稿