学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windowsアプリ)
- iPad
- MyScript Nebo - MyScript(iPadアプリ(iOS))
- 参考書籍
新装版 数学読本2 (松坂 和夫(著)、岩波書店)の第8章(円の中にひそむ関数 - 三角関数)、8.2(加法定理)、三角関数の合成の問20の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, sin, cos, asin, sqrt, pi, Rational, plot
print('20.')
theta = 2
class MyTestCase(TestCase):
def test1(self):
self.assertEqual(float(sqrt(3) * sin(theta) - cos(theta)),
float(2 * sin(theta + 11 * pi / 6)))
def test2(self):
alpha = asin(Rational(4, 5))
self.assertEqual(float(3 * sin(theta) + 4 * cos(theta)),
float(5 * sin(theta + alpha)))
def test3(self):
alpha = asin(-Rational(5, 13))
self.assertEqual(float(5 * sin(theta) + 12 * cos(theta)),
float(13 * cos(theta + alpha)))
def test4(self):
self.assertEqual(float(cos(theta) - sin(theta)),
float(sqrt(2) * cos(theta + pi / 4)))
x = symbols('x')
p = plot(sqrt(3) * sin(x) - cos(x),
3 * sin(x) + 4 * cos(x),
5 * sin(x) + 12 * cos(x),
cos(x) - sin(x),
ylim=(-10, 10),
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'sample20.png')
if __name__ == '__main__':
main()
入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
% ./sample20.py -v
20.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok
test3 (__main__.MyTestCase) ... ok
test4 (__main__.MyTestCase) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.032s
OK
%
0 コメント:
コメントを投稿