2019年12月17日火曜日

学習環境

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



    1. a 2 = b 2 + c 2 - 2 b c cos A = 4 2 + 6 2 - 2 · 4 · 6 cos 2 3 π = 16 + 36 - 48 · - 1 2 = 52 + 24 = 76 a = 76 = 2 19

    2. a 2 = 1 0 2 + 7 2 - 2 · 10 · 7 cos 4 0 100 + 49 - 140 · 0.7660 = 149 - 107.24 = 41.76 a 6.46

    3. c 2 = a 2 + b 2 - 2 a b cos C 63 = 27 + b 2 - 2 · 3 3 b cos 5 6 π b 2 + 9 b - 36 = 0 b = - 9 + 81 + 144 2 = - 9 + 225 2 = - 9 + 15 2 = 3

    4. 49 = 25 + 64 - 80 cos A cos A = 1 2 A = π 3

    5. 64 = 49 + 25 - 70 cos C cos C = 1 7 0.1428 C 8 2

コード

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

コメントを投稿