2019年4月4日木曜日

学習環境

解析入門 原書第3版 (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第4部(級数)、第14章(テイラーの公式)、4(指数関数)の練習問題7の解答を求めてみる。



    1. e 2 < 3 2 = 9 R 4 < 9 · 2 4 4 ! = 6

    2. e 3 < 3 3 = 27 R 4 < 27 · 3 4 4 ! = 27 · 3 3 4 · 2 = 729 8

コード

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, exp, plot, factorial, Derivative, Rational

print('7.')

x = symbols('x')
f = exp(x)
g = sum([Derivative(f, x, i).subs({x: 0}) /
         factorial(i) * x ** i for i in range(4)])
for o in [g, g.doit()]:
    pprint(o)
    print()
xs = [2, 3]
rs = [6, Rational(729, 8)]
for i, (x0, r0) in enumerate(zip(xs, rs)):
    print(f'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('sample7.png')

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

C:\Users\...>py sample8.py
7.
   ⎛  3    ⎞│         ⎛  2    ⎞│                        
 3 ⎜ d ⎛ x⎞⎟│       2 ⎜ d ⎛ x⎞⎟│                        
x ⋅⎜───⎝ℯ ⎠⎟│      x ⋅⎜───⎝ℯ ⎠⎟│                        
   ⎜  3    ⎟│         ⎜  2    ⎟│                        
   ⎝dx     ⎠│x=0      ⎝dx     ⎠│x=0     ⎛d ⎛ x⎞⎞│       
──────────────── + ──────────────── + x⋅⎜──⎝ℯ ⎠⎟│    + 1
       6                  2             ⎝dx    ⎠│x=0    

 3    2        
x    x         
── + ── + x + 1
6    2         

x = 2
                                     ⎛  3    ⎞│       
                                     ⎜ d ⎛ x⎞⎟│       
                                   4⋅⎜───⎝ℯ ⎠⎟│       
                   ⎛  2    ⎞│        ⎜  3    ⎟│       
  ⎛d ⎛ x⎞⎞│        ⎜ d ⎛ x⎞⎟│        ⎝dx     ⎠│x=0    
2⋅⎜──⎝ℯ ⎠⎟│    + 2⋅⎜───⎝ℯ ⎠⎟│    + ─────────────── + 1
  ⎝dx    ⎠│x=0     ⎜  2    ⎟│             3           
                   ⎝dx     ⎠│x=0                      

1.055722765597317

6

True

x = 3
                   ⎛  2    ⎞│        ⎛  3    ⎞│       
                   ⎜ d ⎛ x⎞⎟│        ⎜ d ⎛ x⎞⎟│       
                 9⋅⎜───⎝ℯ ⎠⎟│      9⋅⎜───⎝ℯ ⎠⎟│       
                   ⎜  2    ⎟│        ⎜  3    ⎟│       
  ⎛d ⎛ x⎞⎞│        ⎝dx     ⎠│x=0     ⎝dx     ⎠│x=0    
3⋅⎜──⎝ℯ ⎠⎟│    + ─────────────── + ─────────────── + 1
  ⎝dx    ⎠│x=0          2                 2           

7.085536923187668

729/8

True


C:\Users\...>

0 コメント:

コメントを投稿