2019年12月6日金曜日

学習環境

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



    1. sin 3 θ cos θ = 1 2 sin 3 θ + θ + sin 3 θ - θ = 1 2 sin 4 θ + sin 2 θ

    2. cos θ cos 7 θ = cos 7 θ + θ + cos 7 θ - θ 2 = 1 2 cos 8 θ + cos 6 θ

    3. sin 3 θ sin 2 θ = 1 2 cos 3 θ - 2 θ - cos 3 θ + 2 θ = 1 2 cos θ - cos 5 θ

    4. sin θ + sin 3 θ = sin θ 2 + θ 2 + sin 3 2 θ + 3 2 θ = sin θ 2 + 3 2 θ + θ 2 - 3 2 θ + sin θ 2 + 3 2 θ - θ 2 - 3 2 θ = sin θ 2 + 3 2 θ cos θ 2 - 3 2 θ + cos θ 2 + 3 2 θ sin θ 2 - 3 2 θ + sin θ 2 + 3 2 θ cos θ 2 - 3 2 θ - cos θ 2 + 3 2 θ sin θ 2 - 3 2 θ = 2 sin θ 2 + 3 2 θ cos θ 2 - 3 2 θ = 2 sin 2 θ cos θ

    5. sin 4 θ - sin 2 θ = sin 2 + 1 + 2 - 1 θ - sin 2 + 1 - 2 - 1 θ = sin 3 θ cos θ + cos 3 θ sin θ - sin 3 θ cos θ - cos 3 θ sin θ = 2 cos 3 θ sin θ

    6. cos 9 θ + cos θ = cos 9 2 θ + θ 2 + 9 2 θ - θ 2 + cos 9 2 θ + θ 2 - 9 2 θ - θ 2 = cos 5 θ cos 4 θ - sin 5 θ sin 4 θ + cos 5 θ cos 4 θ + sin 5 θ sin 4 θ = 2 cos 5 θ cos 4 θ

    7. cos 2 α - cos 2 β = cos α + β + α - β - cos α + β - α - β = cos α + β cos α - β - sin α + β sin α - β - cos α + β cos α - β + sin α + β sin α - β = - 2 sin α + β sin α - β

コード

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

print('34.')

x, y = symbols('x, y')
fs = [sin(3 * x) * cos(x),
      cos(x) * cos(7 * x),
      sin(3 * x) * sin(2 * x),
      sin(x) + sin(3 * x),
      sin(4 * x) - sin(2 * x),
      cos(9 * x) + cos(x),
      cos(2 * x) - cos(2 * y)]

gs = [(sin(4 * x) + sin(2 * x)) / 2,
      (cos(8 * x) + cos(6 * x)) / 2,
      (cos(x) - cos(5 * x)) / 2,
      2 * sin(2 * x) * cos(x),
      2 * cos(3 * x) * sin(x),
      2 * cos(5 * x) * cos(4 * x),
      -2 * sin(x + y) * sin(x - y)]

d = {x: 1, y: 2}


class MyTestCase(TestCase):
    def test(self):
        for f, g in zip(fs, gs):
            self.assertEqual(float(f.subs(d)), float(g.subs(d)))


p = plot(*fs[:-1],
         (x, -5, 5),
         ylim=(-5, 5),
         legend=False,
         show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
          'purple', 'pink', 'gray', 'skyblue', 'yellow']

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

for i, o in enumerate(zip(fs[:-1], colors), 1):
    print(f'({i})')
    pprint(o)
    print()

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


if __name__ == '__main__':
    main()

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

% ./sample34.py -v
34.
(1)
(sin(3⋅x)⋅cos(x), red)

(2)
(cos(x)⋅cos(7⋅x), green)

(3)
(sin(2⋅x)⋅sin(3⋅x), blue)

(4)
(sin(x) + sin(3⋅x), brown)

(5)
(-sin(2⋅x) + sin(4⋅x), orange)

(6)
(cos(x) + cos(9⋅x), purple)

test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.019s

OK
%

0 コメント:

コメントを投稿