学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
解析入門(上) (松坂和夫 数学入門シリーズ 4) (松坂 和夫(著)、岩波書店)の第8章(積分の計算)、8.2(定積分の計算)、問題5の解答を求めてみる。
とおくと、
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, Integral, sqrt, pi, log, sin, cos, plot
print('5.')
x = symbols('x')
class MyTestCase(TestCase):
def test1(self):
a = 1
b = 2
self.assertEqual(Integral(1 / sqrt((x - a) * (b - x)), (x, a, b)).doit(),
pi)
def test2(self):
alpha = -1
self.assertEqual(Integral(log(x) / x ** alpha, (x, 0, 1)).doit(),
-1 / (1 - alpha) ** 2)
def test3(self):
a = 2
self.assertEqual(float(Integral(1 / ((1 - 2 * a * x + a ** 2) * sqrt(1 - x ** 2)),
(x, -1, 1)).doit()),
float(pi / abs(1 - a ** 2)))
def test4(self):
self.assertEqual(Integral(sin(x) / (sin(x) + cos(x)), (x, 0, pi / 2)).doit(),
pi / 4)
p = plot(1 / sqrt((x - 1) * (2 - x)),
log(x) / x ** -2,
1 / ((1 - 2 * 3 * x + 3 ** 2) * sqrt(1 - x ** 2)),
sin(x) / (sin(x) + cos(x)),
cos(x) / (sin(x) + cos(x)),
(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('sample5.png')
if __name__ == '__main__':
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample5.py -v
5.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok
test3 (__main__.MyTestCase) ... ok
test4 (__main__.MyTestCase) ... ok
----------------------------------------------------------------------
Ran 4 tests in 18.068s
OK
%
0 コメント:
コメントを投稿