2019年11月16日土曜日

学習環境

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


  1. f x = x 3 + a x 2 + b x + c

    とおく。

    関数 f は連続関数である。

    また、

    f ' x = 3 x 2 + 2 a x + b

    である。

    増減を考える。

    D = a 2 - 3 b < 0

    の とき、

    f ' x > 0

    なので、 f は狭義単調増加関数なので、 十分小さい x に対して、

    f x < 0

    十分大きい x に対して

    f x > 0

    また、

    D 0

    の場合、

    f ' x = 0 x = - a ± a 2 - 3 b 3

    で、増減は

    よって、 同様に十分小さい x、 十分大きい x に対してそれぞれ

    f x < 0 , f x > 0

    ゆえに、中間値の定理より

    f c = 0 c

    を満たす実数 c が存在する。

    (証明終)

コード

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

print('1.')

x, a, b, c = symbols('x, a, b, c', real=True)
f = x ** 3 + a * x ** 2 + b * x + c


class MyTestCase(TestCase):
    def test(self):
        cs = solve(f, x)
        self.assertTrue(cs)


p = plot(*[f.subs({a: random.randrange(-5, 6),
                   b: random.randrange(-5, 6),
                   c: random.randrange(-5, 6)})
           for _ in range(10)],
         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('sample1.png')

if __name__ == '__main__':
    main()

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

% ./sample1.py -v
1.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.059s

OK
%

0 コメント:

コメントを投稿