2019年12月8日日曜日

学習環境

解析入門 原書第3版 (S.ラング(著)、松坂 和夫(翻訳)、片山 孝次(翻訳)、岩波書店)の第Ⅴ部(“ε-δ”その他)、付録2(帰納法)の練習問題2を求めてみる。



    1. k=1nk2=k=1n-1k2+n2=16n-1n2n-1+1=nn-12n-1+6n26=16n2n2-3n+1+6n=16n2n2+3n+1=16nn+12n+1

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

      (証明終)


    2. k=1nk3=k=1n-1k3+n3=n-1n22+n3=122n2n-12+4n=n22n2+2n+1=n22n+12=nn+122

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

      (証明終)

コード

#!/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()

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

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

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

OK
%

0 コメント:

コメントを投稿