学習環境
- Surface、Surface ペン(端末)
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad Pro 10.5 + Apple Pencil
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
解析入門 原書第3版 (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第4部(級数)、第14章(テイラーの公式)、4(指数関数)の練習問題8の解答を求めてみる。
コード
Python 3
#!/usr/bin/env python3 from sympy import pprint, symbols, exp, plot, factorial, Derivative, Rational print('8.') x = symbols('x') f = exp(x) g = sum([Derivative(f, x, i).subs({x: 0}) / factorial(i) * x ** i for i in range(5)]) for o in [g, g.doit()]: pprint(o) print() xs = [2, 3] rs = [Rational(12, 5), Rational(2187, 40)] for i, (x0, r0) in enumerate(zip(xs, rs)): print(f'({chr(ord("a") + i)}) x = {x0}') gx = g.subs({x: x0}) r = (exp(x0) - gx).doit() for o in [gx, float(r), r0, r <= r0]: pprint(o) print() p = plot(f, g.doit(), (x, -5, 5), ylim=(0, 10), show=False, legend=True) colors = ['red', 'green', 'blue', 'brown'] for s, color in zip(p, colors): s.line_color = color p.show() p.save('sample8.png')
入出力結果(cmd(コマンドプロンプト)、Terminal、Jupyter(IPython))
C:\Users\...>py sample8.py 8. ⎛ 4 ⎞│ ⎛ 3 ⎞│ ⎛ 2 ⎞│ 4 ⎜ d ⎛ x⎞⎟│ 3 ⎜ d ⎛ x⎞⎟│ 2 ⎜ d ⎛ x⎞⎟│ x ⋅⎜───⎝ℯ ⎠⎟│ x ⋅⎜───⎝ℯ ⎠⎟│ x ⋅⎜───⎝ℯ ⎠⎟│ ⎜ 4 ⎟│ ⎜ 3 ⎟│ ⎜ 2 ⎟│ ⎝dx ⎠│x=0 ⎝dx ⎠│x=0 ⎝dx ⎠│x=0 ⎛d ⎛ x⎞⎞│ ──────────────── + ──────────────── + ──────────────── + x⋅⎜──⎝ℯ ⎠⎟│ + 1 24 6 2 ⎝dx ⎠│x=0 4 3 2 x x x ── + ── + ── + x + 1 24 6 2 (a) x = 2 ⎛ 3 ⎞│ ⎛ 4 ⎞│ ⎜ d ⎛ x⎞⎟│ ⎜ d ⎛ x⎞⎟│ 4⋅⎜───⎝ℯ ⎠⎟│ 2⋅⎜───⎝ℯ ⎠⎟│ ⎛ 2 ⎞│ ⎜ 3 ⎟│ ⎜ 4 ⎟│ ⎛d ⎛ x⎞⎞│ ⎜ d ⎛ x⎞⎟│ ⎝dx ⎠│x=0 ⎝dx ⎠│x=0 2⋅⎜──⎝ℯ ⎠⎟│ + 2⋅⎜───⎝ℯ ⎠⎟│ + ─────────────── + ─────────────── + 1 ⎝dx ⎠│x=0 ⎜ 2 ⎟│ 3 3 ⎝dx ⎠│x=0 0.38905609893065024 12/5 True (b) x = 3 ⎛ 2 ⎞│ ⎛ 3 ⎞│ ⎛ 4 ⎞│ ⎜ d ⎛ x⎞⎟│ ⎜ d ⎛ x⎞⎟│ ⎜ d ⎛ x⎞⎟│ 9⋅⎜───⎝ℯ ⎠⎟│ 9⋅⎜───⎝ℯ ⎠⎟│ 27⋅⎜───⎝ℯ ⎠⎟│ ⎜ 2 ⎟│ ⎜ 3 ⎟│ ⎜ 4 ⎟│ ⎛d ⎛ x⎞⎞│ ⎝dx ⎠│x=0 ⎝dx ⎠│x=0 ⎝dx ⎠│x=0 3⋅⎜──⎝ℯ ⎠⎟│ + ─────────────── + ─────────────── + ──────────────── + 1 ⎝dx ⎠│x=0 2 2 8 3.710536923187668 2187 ──── 40 True C:\Users\...>
0 コメント:
コメントを投稿