2020年3月23日月曜日

学習環境

新装版 数学読本3 (松坂 和夫(著)、岩波書店)の第10章(新しい数とその表示ー複素数と複素平面)、10.1(複素平面)、複素の絶対値の問2の解答を求めてみる。



    1. - 2 i 3 + i 2 - 4 i 1 + i = - 2 i 3 + i 2 - 4 i 1 + i = 2 · 9 + 1 4 + 16 1 + 1 = 2 2 · 5 2 2 · 5 2 = 40

    2. - 1 + 2 i 3 - 2 i 1 + i 3 - 4 i = 1 + 4 9 + 4 2 25 = 5 13 5 2 = 130 10

コード

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


class MyTestCase(TestCase):
    def test1(self):
        self.assertEqual(abs(-2 * I * (3 + I) * (2 - 4 * I) * (1 + I)), 40)

    def test2(self):
        self.assertEqual(abs(((-1 + 2 * I) * (3 - 2 * I)) /
                             ((1 + I) * (3 - 4 * I))),
                         sqrt(130) / 10)


if __name__ == "__main__":
    main()

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

% ./sample2.py -v
2.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 2 tests in 0.079s

OK
%

0 コメント:

コメントを投稿