## 2019年12月28日土曜日

### 数学 - Python - 微分積分学 - 積分法 - 原始関数 - 累乗、平方根

1. 以下 C はそれぞれ積分定数。

$\begin{array}{l}\int \frac{\mathrm{dx}}{\sqrt{x}}\\ =2\sqrt{x}+C\end{array}$

2. $\begin{array}{l}\int {x}^{3}\sqrt{x}\mathrm{dx}\\ =\int {x}^{\frac{7}{2}}\mathrm{dx}\\ =\frac{2}{9}{x}^{\frac{9}{2}}+C\\ =\frac{2}{9}{x}^{4}\sqrt{x}+C\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, plot, Integral, sqrt, Rational

print('1.')

x = symbols('x')
fs = [1 / sqrt(x),
x ** 3 * sqrt(x)]

class MyTestCase(TestCase):
def test1(self):
self.assertEqual(Integral(fs[0], x).doit(), 2 * sqrt(x))

def test2(self):
i = Integral(fs[1], x).doit()
self.assertEqual(i, 2 * x ** Rational(9, 2) / 9)
self.assertEqual(i, 2 * x ** 4 * sqrt(x) / 9)

p = plot(*fs,
(x, 0, 5),
ylim=(0, 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('sample1.png')

if __name__ == '__main__':
main()


% ./sample1.py -v
1.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.016s

OK
%