2020年2月17日月曜日

学習環境

代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第4章(1次方程式, 2次方程式 )、4(解の公式、解の虚実)の問17の解答を求めてみる。


  1.  

    • a>0,b<0

      の場合、

      ab=a-1-b=a-bi=--abiab=--ab=-abi

      よって、

      ab-ab

    • a<0,b>0

      の場合。

      ab=-aib=-abiab=-ab-1=-abiab=ab

    • a<0,b<0

      のとき、

      ab=-a-1-b-1=-ai-bi=ab

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, sqrt, I

print('17.')


class MyTestCase(TestCase):
    def test1(self):
        a = 1
        b = -1
        self.assertEqual(sqrt(a) / sqrt(b) - (-sqrt(-a / b) * I), 0)
        self.assertNotEqual(sqrt(a) / sqrt(b), sqrt(- a / b))

    def test2(self):
        a = symbols('a', negative=True)
        b = symbols('b', positive=True)
        self.assertEqual(sqrt(a) / sqrt(b), sqrt(a / b))
        self.assertNotEqual(sqrt(a) / sqrt(b), sqrt(- a / b))

    def test3(self):
        a, b = symbols('a, b', negative=True)
        self.assertEqual((sqrt(a) / sqrt(b) - sqrt(a / b)).simplify(), 0)


if __name__ == "__main__":
    main()

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

% ./sample17.py -v
17.
test1 (__main__.MyTestCase) ... ok
test2 (__main__.MyTestCase) ... ok
test3 (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.326s

OK
%

0 コメント:

コメントを投稿