## 2020年7月17日金曜日

### 数学 - Python - 微分積分学 - 積分法 - 不定積分の計算 - 累乗

1. $\int \left(2{x}^{3}-5{x}^{2}-3x+4\right)\mathrm{dx}$
$=\frac{1}{2}{x}^{4}-\frac{5}{3}{x}^{3}-\frac{3}{2}{x}^{2}+4x+C$

2. $\int \left(2{x}^{\frac{3}{2}}-3{x}^{\frac{2}{3}}+5{x}^{\frac{1}{2}}-3\right)\mathrm{dx}$
$=\frac{4}{5}{x}^{\frac{5}{2}}-\frac{9}{5}{x}^{\frac{5}{3}}+\frac{10}{3}{x}^{\frac{3}{2}}-3x+C$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Rational
from sympy.abc import x

print('1, 2.')

class Test(TestCase):
def test1(self):
self.assertEqual(
(2 * x ** 3 - 5 * x ** 2 - 3 * x + 4).integrate(x),
x ** 4 / 2 - 5 * x ** 3 / 3 - 3 * x ** 2 / 2 + 4 * x
)

def test2(self):
self.assertEqual(
(2 * x ** Rational(3, 2) - 3 * x ** Rational(2, 3) +
5 * x ** Rational(1, 2) - 3).integrate(x),
4 * x ** Rational(5, 2) / 5 - 9 * x ** Rational(5, 3) /
5 + 10 * x ** Rational(3, 2) / 3 - 3 * x
)

if __name__ == "__main__":
main()


% ./sample1.py -v
1, 2.
test1 (__main__.Test) ... ok
test2 (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.039s

OK
%