## 2019年9月20日金曜日

### 数学 - Python - 微分積分学 - 微分法の公式 - 微分法の公式 - 関数の和の導関数、関数の積の導関数

1. $\begin{array}{l}\frac{1}{2\sqrt{x}}\left(1+3{x}^{2}+2{x}^{3}\right)+\sqrt{x}\left(6x+6{x}^{2}\right)\\ =\frac{1}{2\sqrt{x}}\left(1+3{x}^{2}+2{x}^{3}+12{x}^{2}+12{x}^{3}\right)\\ =\frac{1}{2\sqrt{x}}\left(1+15{x}^{2}+14{x}^{3}\right)\end{array}$

2. $\begin{array}{l}\left(3{x}^{2}+2\right)\left({x}^{2}+6x+1\right)\\ +\left({x}^{3}+2x+5\right)\left(2x+6\right)\\ =3{x}^{4}+18{x}^{3}+5{x}^{2}+12x+2\\ +2{x}^{4}+6{x}^{3}+4{x}^{2}+22x+30\\ =5{x}^{4}+24{x}^{3}+9{x}^{2}+34x+32\end{array}$

コード

Python 3

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

print('1.')

class MyTest(TestCase):
def setUp(self):
pass

def tearDown(self):
pass

def test(self):
x = symbols('x')
fs = [sqrt(x) * (1 + 3 * x ** 2 + 2 * x ** 3),
(x ** 3 + 2 * x + 5) * (x ** 2 + 6 * x + 1)]
dfs = [[c / (2 * sqrt(x)) for c in [1, 0, 15, 14]],
(32, 34, 9, 24, 5)]
for f, df in zip(fs, dfs):
self.assertEqual(
Derivative(f, x, 1).doit().expand(),
sum([c * x ** i for i, c in enumerate(df)]).expand())

if __name__ == '__main__':
main()

C:\Users\...>py sample1.py
1.
.
----------------------------------------------------------------------
Ran 1 test in 0.038s

OK

c:\Users\...>