## 2019年8月31日土曜日

### 数学 - Python - 解析学 - 級数 - 絶対収束と交代級数の収束 - 余弦、階乗

1. $\left|\frac{1+\mathrm{cos}\pi n}{n!}\right|\le \frac{2}{n!}$

が成り立ち、

$\sum \frac{2}{n!}$

は収束するので、絶対収束。

コード

Python 3

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

print('2.')

n = symbols('n')
f = abs((1 + cos(pi * n)) / factorial(n))
s = summation(f, (n, 1, oo))
I = Integral(f, (n, 1, oo))

for o in [s, I  # , I.doit()
]:
pprint(o)
print()

p = plot(f,
(n, 1, 11),
legend=True,
show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']

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

p.show()
p.save('sample2.png')

def g(m):
return sum([f.subs({n: k}) for k in range(1, m)])

ms = range(1, 11)
plt.plot(ms, [g(m) for m in ms])
plt.legend(['Σ |1 + cos πn / n!|', '|1 + cos πn / n!|'])
plt.savefig('sample2.png')


C:\Users\...>py sample2.py
2.
∞
____
╲
╲   │cos(π⋅n) + 1│
╲  │────────────│
╱  │     n!     │
╱
╱
‾‾‾‾
n = 1

∞
⌠
⎮ │cos(π⋅n) + 1│
⎮ │────────────│ dn
⎮ │     n!     │
⌡
1

c:\Users\...>