学習環境
微分積分学 (ちくま学芸文庫) (吉田 洋一(著)、筑摩書房)のⅡ.(微分法の公式)、1.(微分法の公式)、問1の解答を求めてみる。
12√x(1+3x2+2x3)+√x(6x+6x2)=12√x(1+3x2+2x3+12x2+12x3)=12√x(1+15x2+14x3)
(3x2+2)(x2+6x+1)+(x3+2x+5)(2x+6)=3x4+18x3+5x2+12x+2+2x4+6x3+4x2+22x+30=5x4+24x3+9x2+34x+32
コード
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()
入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))
C:\Users\...>py sample1.py
1.
.
----------------------------------------------------------------------
Ran 1 test in 0.038s
OK
c:\Users\...>
0 コメント:
コメントを投稿