2019年6月14日金曜日

学習環境

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


  1. e x = 1 + x + 1 2 ! x 2 + e - 2 = 1 + - 2 + 1 2 ! - 2 2 + 1 3 ! - 2 3 = - 1 3 - 2 2 = - 4 3 1 4 ! - 2 4 = 2 3 1 5 ! - 2 5 = - 4 15 1 6 ! - 2 6 = 4 45 1 7 ! - 2 7 = - 8 315 1 8 ! - 2 8 = 2 315 1 9 ! - 2 9 = - 4 2835 1 10 ! - 2 10 = 4 14175 < 1 0 - 4

    よって、 求める値は、

    1 - 2 + 2 - 4 3 + 2 3 - 4 15 + 4 45 - 8 315 + 2 315 - 4 2835

コード

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, plot, factorial, exp, summation
import matplotlib.pyplot as plt

print('17.')

k, n = symbols('k, n', integer=True)
f = summation(1 / factorial(k) * (-2) ** k, (k, 0, n))
for i in range(11):
    a = f.subs({n: i})
    for o in [a, float(a)]:
        pprint(o)
        print()

pprint(float(1 / exp(2)))

p = plot(1 / exp(2), *[f.subs({n: i}) for i in range(4, 10)],
         legend=False,
         show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
          'purple', 'pink', 'gray', 'skyblue', 'yellow']

for o, color in zip(p, colors):
    o.line_color = color


def f(n):
    return sum([1 / factorial(n0) * (-2) ** n0 for n0 in range(n)])


ns = range(11)

plt.plot(ns, [1 / exp(2) for _ in ns], ns, [f(n) for n in ns])
plt.savefig('sample17.png')

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

C:\Users\...>py sample17.py
17.
 -2   ⎛     2⎞  -2
ℯ   - ⎝1 - ℯ ⎠⋅ℯ  

1.0

  ⎛     2⎞  -2    -2
- ⎝1 + ℯ ⎠⋅ℯ   + ℯ  

-1.0

      ⎛       2⎞  -2
 -2   ⎝2 - 2⋅ℯ ⎠⋅ℯ  
ℯ   - ──────────────
            2       

1.0

  ⎛       2⎞  -2      
  ⎝6 + 2⋅ℯ ⎠⋅ℯ      -2
- ────────────── + ℯ  
        6             

-0.3333333333333333

      ⎛        2⎞  -2
 -2   ⎝24 - 8⋅ℯ ⎠⋅ℯ  
ℯ   - ───────────────
             24      

0.3333333333333333

  ⎛         2⎞  -2      
  ⎝120 - 8⋅ℯ ⎠⋅ℯ      -2
- ──────────────── + ℯ  
        120             

0.06666666666666667

  ⎛           2⎞  -2      
  ⎝720 - 112⋅ℯ ⎠⋅ℯ      -2
- ────────────────── + ℯ  
         720              

0.15555555555555556

  ⎛            2⎞  -2      
  ⎝5040 - 656⋅ℯ ⎠⋅ℯ      -2
- ─────────────────── + ℯ  
          5040             

0.13015873015873017

  ⎛              2⎞  -2      
  ⎝40320 - 5504⋅ℯ ⎠⋅ℯ      -2
- ───────────────────── + ℯ  
          40320              

0.13650793650793652

  ⎛                2⎞  -2      
  ⎝362880 - 49024⋅ℯ ⎠⋅ℯ      -2
- ─────────────────────── + ℯ  
           362880              

0.13509700176366843

  ⎛                  2⎞  -2      
  ⎝3628800 - 491264⋅ℯ ⎠⋅ℯ      -2
- ───────────────────────── + ℯ  
           3628800               

0.13537918871252205

0.1353352832366127


C:\Users\...>

0 コメント:

コメントを投稿