## 2020年8月6日木曜日

### 数学 - Python - 微分積分学 - 積分法 - 偶関数と奇関数、定積分、等式

• ${\int }_{-a}^{a}f\left(x\right)\mathrm{dx}$
$={\int }_{-a}^{0}f\left(x\right)\mathrm{dx}+{\int }_{0}^{a}f\left(x\right)\mathrm{dx}$
$={\int }_{0}^{a}f\left(-x\right)\mathrm{dx}+{\int }_{0}^{a}f\left(x\right)\mathrm{dx}$
$={\int }_{0}^{a}f\left(x\right)\mathrm{dx}+{\int }_{0}^{a}f\left(x\right)\mathrm{dx}$
$={\int }_{0}^{a}f\left(x\right)\mathrm{dx}$

• ${\int }_{-a}^{a}f\left(x\right)\mathrm{dx}$
$={\int }_{-a}^{0}f\left(x\right)\mathrm{dx}+{\int }_{0}^{a}f\left(x\right)\mathrm{dx}$
$={\int }_{0}^{a}f\left(-x\right)\mathrm{dx}+{\int }_{0}^{a}f\left(x\right)\mathrm{dx}$
$={\int }_{0}^{a}\left(-f\left(x\right)\right)\mathrm{dx}+{\int }_{0}^{a}f\left(x\right)\mathrm{dx}$
$=-{\int }_{0}^{a}f\left(x\right)\mathrm{dx}+{\int }_{0}^{a}f\left(x\right)\mathrm{dx}$
$=0$

コード

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

print('12.')

f = x ** 2
g = x ** 3

class Test(TestCase):
def test1(self):
self.assertEqual(Integral(f, (x, -a, a)).doit(),
2 * Integral(f, (x, 0, a)).doit())

def test2(self):
self.assertEqual(Integral(g, (x, -a, a)).doit(), 0)

if __name__ == "__main__":
main()


% ./sample12.py -v
12.
test1 (__main__.Test) ... ok
test2 (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.021s

OK
%