## 2020年1月10日金曜日

### 数学 - Python - 解析学 - 積分の計算 - 定積分の計算 - 連続関数、周期関数(三角関数(正弦と余弦)等)

1. $\begin{array}{l}{\int }_{a}^{b}f\left(x\right)\mathrm{dx}\\ ={\int }_{a}^{0}f\left(x\right)\mathrm{dx}+{\int }_{0}^{p}f\left(x\right)\mathrm{dx}+{\int }_{p}^{b}f\left(x\right)\mathrm{dx}\\ =-{\int }_{0}^{a}f\left(x\right)\mathrm{dx}+{\int }_{0}^{p}f\left(x\right)\mathrm{dx}+{\int }_{p}^{a+p}f\left(x\right)\mathrm{dx}\\ ={\int }_{0}^{p}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}^{p}f\left(x\right)\mathrm{dx}\end{array}$

（証明終）

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, sin, cos, pi, Integral, plot

print('2.')

x = symbols('x')
f = sin(x)
g = cos(x)
t = 2 * pi
a = symbols('a')
b = a + t

class MyTestCase(TestCase):
def test_sin(self):
self.assertEqual(Integral(f, (x, a, b)).doit(),
Integral(f, (x, 0, t)).doit())

def test_cos(self):
self.assertEqual(Integral(g, (x, a, b)).doit(),
Integral(g, (x, 0, t)).doit())

p = plot(f, g,
(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('sample2.png')

if __name__ == '__main__':
main()


% ./sample2.py -v
2.
test_cos (__main__.MyTestCase) ... ok
test_sin (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.049s

OK
%