2020年7月17日金曜日

学習環境

微分積分学 (ちくま学芸文庫) (吉田 洋一(著)、筑摩書房)のⅣ.(積分法)、演習問題1、2.の解答を求めてみる。


  1. ( 2 x 3 - 5 x 2 - 3 x + 4 ) dx
    = 1 2 x 4 - 5 3 x 3 - 3 2 x 2 + 4 x + C

  2. ( 2 x 3 2 - 3 x 2 3 + 5 x 1 2 - 3 ) dx
    = 4 5 x 5 2 - 9 5 x 5 3 + 10 3 x 3 2 - 3 x + C

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import Rational
from sympy.abc import x

print('1, 2.')


class Test(TestCase):
    def test1(self):
        self.assertEqual(
            (2 * x ** 3 - 5 * x ** 2 - 3 * x + 4).integrate(x),
            x ** 4 / 2 - 5 * x ** 3 / 3 - 3 * x ** 2 / 2 + 4 * x
        )

    def test2(self):
        self.assertEqual(
            (2 * x ** Rational(3, 2) - 3 * x ** Rational(2, 3) +
             5 * x ** Rational(1, 2) - 3).integrate(x),
            4 * x ** Rational(5, 2) / 5 - 9 * x ** Rational(5, 3) /
            5 + 10 * x ** Rational(3, 2) / 3 - 3 * x
        )


if __name__ == "__main__":
    main()

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

% ./sample1.py -v
1, 2.
test1 (__main__.Test) ... ok
test2 (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.039s

OK
%

0 コメント:

コメントを投稿