2019年12月17日火曜日

学習環境

新装版 数学読本2 (松坂 和夫(著)、岩波書店)の第8章(円の中にひそむ関数 - 三角関数)、8.3(三角関数と三角形)、余弦定理の問40の解答を求めてみる。



    1. a2=b2+c2-2bccosA=42+62-2·4·6cos23π=16+36-48·-12=52+24=76a=76=219

    2. a2=102+72-2·10·7cos40100+49-140·0.7660=149-107.24=41.76a6.46

    3. c2=a2+b2-2abcosC63=27+b2-2·33bcos56πb2+9b-36=0b=-9+81+1442=-9+2252=-9+152=3

    4. 49=25+64-80cosAcosA=12A=π3

    5. 64=49+25-70cosCcosC=170.1428C82

コード

#!/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 コメント:

コメントを投稿