## 2019年12月6日金曜日

### 数学 - Python - 円の中にひそむ関数 - 三角関数 - 加法定理 - 三角関数の諸公式 - 正弦と余弦、積を和または差に、和または差を積に変形、倍角、半角

1. $\begin{array}{l}\mathrm{sin}3\theta \mathrm{cos}\theta \\ =\frac{1}{2}\left(\mathrm{sin}\left(3\theta +\theta \right)+\mathrm{sin}\left(3\theta -\theta \right)\right)\\ =\frac{1}{2}\left(\mathrm{sin}4\theta +\mathrm{sin}2\theta \right)\end{array}$

2. $\begin{array}{l}\mathrm{cos}\theta \mathrm{cos}7\theta \\ =\frac{\mathrm{cos}\left(7\theta +\theta \right)+\mathrm{cos}\left(7\theta -\theta \right)}{2}\\ =\frac{1}{2}\left(\mathrm{cos}8\theta +\mathrm{cos}6\theta \right)\end{array}$

3. $\begin{array}{l}\mathrm{sin}3\theta \mathrm{sin}2\theta \\ =\frac{1}{2}\left(\mathrm{cos}\left(3\theta -2\theta \right)-\mathrm{cos}\left(3\theta +2\theta \right)\right)\\ =\frac{1}{2}\left(\mathrm{cos}\theta -\mathrm{cos}5\theta \right)\end{array}$

4. $\begin{array}{l}\mathrm{sin}\theta +\mathrm{sin}3\theta \\ =\mathrm{sin}\left(\frac{\theta }{2}+\frac{\theta }{2}\right)+\mathrm{sin}\left(\frac{3}{2}\theta +\frac{3}{2}\theta \right)\\ =\mathrm{sin}\left(\left(\frac{\theta }{2}+\frac{3}{2}\theta \right)+\left(\frac{\theta }{2}-\frac{3}{2}\theta \right)\right)+\mathrm{sin}\left(\left(\frac{\theta }{2}+\frac{3}{2}\theta \right)-\left(\frac{\theta }{2}-\frac{3}{2}\theta \right)\right)\\ =\mathrm{sin}\left(\frac{\theta }{2}+\frac{3}{2}\theta \right)\mathrm{cos}\left(\frac{\theta }{2}-\frac{3}{2}\theta \right)+\mathrm{cos}\left(\frac{\theta }{2}+\frac{3}{2}\theta \right)\mathrm{sin}\left(\frac{\theta }{2}-\frac{3}{2}\theta \right)\\ +\mathrm{sin}\left(\frac{\theta }{2}+\frac{3}{2}\theta \right)\mathrm{cos}\left(\frac{\theta }{2}-\frac{3}{2}\theta \right)-\mathrm{cos}\left(\frac{\theta }{2}+\frac{3}{2}\theta \right)\mathrm{sin}\left(\frac{\theta }{2}-\frac{3}{2}\theta \right)\\ =2\mathrm{sin}\left(\frac{\theta }{2}+\frac{3}{2}\theta \right)\mathrm{cos}\left(\frac{\theta }{2}-\frac{3}{2}\theta \right)\\ =2\mathrm{sin}2\theta \mathrm{cos}\theta \end{array}$

5. $\begin{array}{l}\mathrm{sin}4\theta -\mathrm{sin}2\theta \\ =\mathrm{sin}\left(\left(2+1\right)+\left(2-1\right)\right)\theta -\mathrm{sin}\left(\left(2+1\right)-\left(2-1\right)\right)\theta \\ =\mathrm{sin}3\theta \mathrm{cos}\theta +\mathrm{cos}3\theta \mathrm{sin}\theta \\ -\left(\mathrm{sin}3\theta \mathrm{cos}\theta -\mathrm{cos}3\theta \mathrm{sin}\theta \right)\\ =2\mathrm{cos}3\theta \mathrm{sin}\theta \end{array}$

6. $\begin{array}{l}\mathrm{cos}9\theta +\mathrm{cos}\theta \\ =\mathrm{cos}\left(\left(\frac{9}{2}\theta +\frac{\theta }{2}\right)+\left(\frac{9}{2}\theta -\frac{\theta }{2}\right)\right)+\mathrm{cos}\left(\left(\frac{9}{2}\theta +\frac{\theta }{2}\right)-\left(\frac{9}{2}\theta -\frac{\theta }{2}\right)\right)\\ =\mathrm{cos}5\theta \mathrm{cos}4\theta -\mathrm{sin}5\theta \mathrm{sin}4\theta \\ +\mathrm{cos}5\theta \mathrm{cos}4\theta +\mathrm{sin}5\theta \mathrm{sin}4\theta \\ =2\mathrm{cos}5\theta \mathrm{cos}4\theta \end{array}$

7. $\begin{array}{l}\mathrm{cos}2\alpha -\mathrm{cos}2\beta \\ =\mathrm{cos}\left(\left(\alpha +\beta \right)+\left(\alpha -\beta \right)\right)-\mathrm{cos}\left(\left(\alpha +\beta \right)-\left(\alpha -\beta \right)\right)\\ =\mathrm{cos}\left(\alpha +\beta \right)\mathrm{cos}\left(\alpha -\beta \right)-\mathrm{sin}\left(\alpha +\beta \right)\mathrm{sin}\left(\alpha -\beta \right)\\ -\left(\mathrm{cos}\left(\alpha +\beta \right)\mathrm{cos}\left(\alpha -\beta \right)+\mathrm{sin}\left(\alpha +\beta \right)\mathrm{sin}\left(\alpha -\beta \right)\right)\\ =-2\mathrm{sin}\left(\alpha +\beta \right)\mathrm{sin}\left(\alpha -\beta \right)\end{array}$

コード

#!/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()


% ./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
%