2019年11月23日土曜日

学習環境

微分積分学 (ちくま学芸文庫) (吉田 洋一(著)、筑摩書房)のⅢ.(平均値の定理)、演習問題Ⅲ、問2.の解答を求めてみる。


  1. f x = x 3 - 2 x 2 + 5 f ' x = 3 x 2 - 4 x = x 3 x - 4 f ' x = 0 x = 0 , 4 3 f 0 = 5 > 0 f 4 3 = 4 3 3 - 2 4 3 2 + 5 = 64 27 - 32 27 + 135 27 > 0

    よって、 方程式

    x 3 - 2 x 2 + 5 = 0

    は1個の実根をもつ。

コード

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

print('2.')

x = symbols('x', real=True)
f = x ** 3 - 2 * x ** 2 + 5


class MyTestCase(TestCase):
    def test(self):
        xs = solveset(f, x, domain=S.Reals)
        self.assertEqual(len(xs), 1)


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

if __name__ == '__main__':
    main()

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

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

----------------------------------------------------------------------
Ran 1 test in 0.132s

OK
%

0 コメント:

コメントを投稿