## 2020年1月7日火曜日

### 数学 - Python - 微分積分学 - 積分法 - 不定積分の公式 - 部分積分法、累乗の積、漸化式

1. $\begin{array}{l}{I}_{m,n}\\ =\int {\left(ax+b\right)}^{m}{x}^{n}\mathrm{dx}\\ =\frac{{\left(ax+b\right)}^{m}{x}^{n+1}}{n+1}-\frac{1}{n+1}\int m{\left(ax+b\right)}^{m-1}a{x}^{n+1}\mathrm{dx}\\ =\frac{{\left(ax+b\right)}^{m}{x}^{n+1}}{n+1}-\frac{ma}{n+1}\int {\left(ax+b\right)}^{m-1}{x}^{n+1}\mathrm{dx}\\ =\frac{{\left(a+b\right)}^{m}{x}^{n+1}}{n+1}-\frac{ma}{n+1}{I}_{m-1,n+1}\end{array}$

コード

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

print('3.')

x, a, b = symbols('x, a, b')
m, n = symbols('m, n', integer=True, nonnegative=True)

f = (a * x + b) ** m * x ** n
g = Derivative((a * x + b) ** m * x ** (n + 1) / (n + 1), x,
1).doit() - m * a / (n + 1) * f.subs({m: m-1, n: n + 1})

class MyTestCase(TestCase):
def test(self):
self.assertEqual(f.simplify(), g.simplify())

p = plot(f.subs({a: 1, b: 2, m: 1, n: 2}),
(x, -5, 5),
ylim=(0, 10),
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('sample4.png')

if __name__ == '__main__':
main()


% ./sample4.py -v
3.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.344s

OK
%