2019年11月29日金曜日

学習環境

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



    1. 0θ<2πsinθ=sin2θsinθ=2sinθcosθsinθ2cosθ-1=0sinθ=0cosθ=12θ=0,π,π3,53π

    2. sinθ-cos2θ=0sinθ-cos2θ-sin2θ=0sinθ-1-2sin2θ=02sin2θ+sinθ-1=02sinθ-1sinθ+1=0sinθ=-1,12θ=32π,π6,56π

    3. cos2θ-3cosθ-1=0cos2θ-sin2θ-3cosθ-1=02cos2θ-3cosθ-2=02cosθ+1cosθ-2=0cosθ=-12θ=23π,43π

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, sin, cos, solveset, pi, Interval, plot

print('30.')

theta = symbols('θ')
domain = Interval.Ropen(0, 2 * pi)
f1 = sin(theta) - sin(2 * theta)
f2 = sin(theta) - cos(2 * theta)
f3 = cos(2 * theta) - 3 * cos(theta) - 1
fs = [f1, f2, f3]


class MyTestCase(TestCase):
    def test1(self):
        self.assertEqual(solveset(f1, theta, domain=domain),
                         {0, pi, pi / 3, 5 * pi / 3})

    def test2(self):
        self.assertEqual(solveset(f2, theta, domain=domain),
                         {3 * pi / 2, pi / 6, 5 * pi / 6})

    def test3(self):
        self.assertEqual(solveset(f3, theta, domain=domain),
                         {2 * pi / 3, 4 * pi / 3})


p = plot(*fs,
         (theta, 0, 2 * pi),
         ylim=(-pi, pi),
         legend=True,
         show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
          'purple', 'pink', 'gray', 'skyblue', 'yellow']

for s, color in zip(p, colors):
    s.line_color = color

p.show()
p.save(f'sample30.png')

if __name__ == '__main__':
    main()

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

% ./sample30.py -v
30.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok
test3 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 3 tests in 1.357s

OK
%

0 コメント:

コメントを投稿