学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windowsアプリ)
- iPad
- MyScript Nebo - MyScript(iPadアプリ(iOS))
- 参考書籍
新装版 数学読本2 (松坂 和夫(著)、岩波書店)の第8章(円の中にひそむ関数 - 三角関数)、8.2(加法定理)、三角関数の諸公式の問34の解答を求めてみる。
コード
#!/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 コメント:
コメントを投稿