## 2019年12月8日日曜日

### 数学 - Python - 解析学 - “ε-δ”その他 - 帰納法 - 平方、立方の級数

1. $\begin{array}{l}\sum _{k=1}^{n}{k}^{2}\\ =\sum _{k=1}^{n-1}{k}^{2}+{n}^{2}\\ =\frac{1}{6}\left(n-1\right)n\left(2\left(n-1\right)+1\right)\\ =\frac{n\left(n-1\right)\left(2n-1\right)+6{n}^{2}}{6}\\ =\frac{1}{6}n\left(2{n}^{2}-3n+1+6n\right)\\ =\frac{1}{6}n\left(2{n}^{2}+3n+1\right)\\ =\frac{1}{6}n\left(n+1\right)\left(2n+1\right)\end{array}$

よって帰納法によりすべての正の整数について問題の等式は成り立つ。

（証明終）

2. $\begin{array}{l}\sum _{k=1}^{n}{k}^{3}\\ =\sum _{k=1}^{n-1}{k}^{3}+{n}^{3}\\ ={\left(\frac{\left(n-1\right)n}{2}\right)}^{2}+{n}^{3}\\ =\frac{1}{{2}^{2}}{n}^{2}\left({\left(n-1\right)}^{2}+4n\right)\\ ={\left(\frac{n}{2}\right)}^{2}\left({n}^{2}+2n+1\right)\\ ={\left(\frac{n}{2}\right)}^{2}{\left(n+1\right)}^{2}\\ ={\left(\frac{n\left(n+1\right)}{2}\right)}^{2}\end{array}$

よって帰納法により成り立つ。

（証明終）

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import pprint, symbols, plot, summation
print('2.')

n, k = symbols('n, k', integer=True, positive=True)
square = summation(k ** 2, (k, 1, n))
cube = summation(k ** 3, (k, 1, n))

class MyTestCase(TestCase):
def test_a(self):
self.assertEqual(square,  (n * (n + 1) * (2 * n + 1) / 6).expand())

def test_b(self):
self.assertEqual(cube, ((n * (n + 1) / 2) ** 2).expand())

p = plot(square, cube,
(n, 1, 11),
show=False,
legend=True)
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('sample2.png')

if __name__ == '__main__':
main()


% ./sample2.py -v
2.
test_a (__main__.MyTestCase) ... ok
test_b (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.004s

OK
%