2019年11月9日土曜日

学習環境

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



    1. sin15=sin60-45=sin13π-14π=sinπ3cosπ4-cosπ3sinπ4=32·12-12·12=3-122=6-24

    2. cos15=cosπ12=cos13π-14π=cosπ3cosπ4+sinπ3sinπ4=12·12+32·12=3+122=6+24

    3. sin105=sin712π=sinπ2+π12=sinπ2cosπ12+cosπ2sinπ12=6+24

    4. cos105=cos712π=-sin712π-π2=-sinπ12=2-64

    5. sin120=sin23π=32

    6. cos120=cos23π=-12

    7. sin165=sin165180π=sin1112π=sin1012π+112π=sin56π+π12=sin56πcosπ12+cos56πsinπ12=12·6+24-32·6-24=6+2-18+68=26+2-328=26-228=6-24

    8. cos165=cos1112π=-cos1112π-π=-cos-π12=-cosπ12=-6+24

コード

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

print('16.')


class MyTestCase(TestCase):

    def test(self):
        angles = [15, 105, 120, 165]
        fs = [sin, cos]
        results = [(sqrt(6) - sqrt(2)) / 4,
                   (sqrt(6) + sqrt(2)) / 4,
                   (sqrt(6) + sqrt(2)) / 4,
                   (sqrt(2) - sqrt(6)) / 4,
                   sqrt(3) / 2,
                   -Rational(1, 2),
                   (sqrt(6) - sqrt(2)) / 4,
                   -(sqrt(6) + sqrt(2)) / 4]
        for i, angle in enumerate(angles):
            for j, f in enumerate(fs):
                self.assertAlmostEqual(f(math.radians(angle)),
                                       float(results[2 * i + j]))


if __name__ == '__main__':
    main()

入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))

% ./sample16.py -v
16.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.011s

OK
%

0 コメント:

コメントを投稿