Loading [MathJax]/jax/output/CommonHTML/jax.js

2019年10月3日木曜日

学習環境

微分積分学 (ちくま学芸文庫) (吉田 洋一(著)、筑摩書房)のⅡ.(微分法の公式)、6.(導関数の求め方)、演習問題I7の解答を求めてみる。


  1. ddx(x+1)2(x+2)3(x+3)4=(x+1)2(x+2)3(x+3)4(2·1x+1-3·1x+2-4·1x+3)=(x+1)2(x+2)3(x+3)4·2(x+2)(x+3)-3(x+1)(x+3)-4(x+1)(x+2)(x+1)(x+2)(x+3)=(x+1)(-5x2-14x-5)(x+2)4(x+3)5=-(x+1)(5x2+14x+5)(x+2)4(x+3)5

コード

Python 3

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

print('17.')

x = symbols('x')
f = (x + 1) ** 2 / ((x + 2) ** 3 * (x + 3) ** 4)
d = Derivative(f, x, 1).doit()


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

    def tearDown(self):
        pass

    def test(self):
        d0 = -(x + 1) * (5 * x ** 2 + 14 * x + 5) / \
            ((x + 2) ** 4 * (x + 3) ** 5)
        self.assertEqual(d.factor(), d0.factor())


p = plot(f, d,
         ylim=(-10, 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('sample17.png')

if __name__ == '__main__':
    main()

入出力結果(Bash、cmd.exe(コマンドプロンプト)、Terminal、Jupyter(IPython))

$ ./sample17.py
17.
.
----------------------------------------------------------------------
Ran 1 test in 0.023s

OK
$ 

0 コメント:

コメントを投稿