学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
解析入門(上) (松坂和夫 数学入門シリーズ 4) (松坂 和夫(著)、岩波書店)の第8章(積分の計算)、8.1(不定積分の計算)、問題7の解答を求めてみる。
よって、
置換積分と部分分数分解。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, Derivative, sin, cos, tan, atan, log, plot
print('7.')
x = symbols('x')
fs = [1 / (1 + cos(x)),
1 / cos(x),
sin(x) / (1 + sin(x))]
gs = [tan(x / 2),
log(abs((1 + tan(x / 2)) / (1 - tan(x / 2)))),
x + 2 / (1 + tan(x / 2))]
s = {x: 1}
class MyTestCase(TestCase):
def test1(self):
self.assertEqual(float(fs[0].subs(s)),
float(Derivative(gs[0], x, 1).doit().subs(s)))
def test2(self):
self.assertEqual(float(fs[1].subs(s)),
float(Derivative(log((1 + tan(x / 2)) /
(1 - tan(x / 2))), x, 1).doit().subs(s)))
def test3(self):
self.assertEqual(float(fs[2].subs(s)),
float(Derivative(gs[2], x, 1).doit().subs(s)))
p = plot(*[f for f in fs + gs],
(x, -5, 5),
ylim=(-5, 5),
legend=True,
show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']
for o, color in zip(p, colors):
o.line_color = color
p.show()
p.save('sample7.png')
if __name__ == '__main__':
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample7.py -v
7.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok
test3 (__main__.MyTestCase) ... ok
----------------------------------------------------------------------
Ran 3 tests in 0.044s
OK
%
0 コメント:
コメントを投稿