学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第5章(連立方程式と高次方程式)、問6の解答を求めてみる。
(複号同順)
(複号同順)
(複号同順)
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, solve, Rational, I, sqrt
print('6.')
a, b = symbols('a:b', real=True)
class TestImaginaryNumbers(TestCase):
def test1(self):
self.assertEqual(
solve(((a + b) + a * b * I) - (4 + 2 * I)),
[{a: 2-sqrt(2), b: 2+sqrt(2)},
{a: 2+sqrt(2), b: 2-sqrt(2)}]
)
def test2(self):
self.assertEqual(
solve((a + b * I) ** 2 - (15 - 8 * I)),
[{a: -4, b: 1},
{a: 4, b: -1}]
)
def test3(self):
self.assertEqual(
solve(((1 + 3 * I) * a ** 2 + (2 - I) *
a * b + (3 - 2 * I) * b ** 2) - 19),
[{a: -2, b: 3},
{a: 2, b: -3},
{a: -sqrt(Rational(19, 6)), b: -sqrt(Rational(19, 6))},
{a: sqrt(Rational(19, 6)), b: sqrt(Rational(19, 6))}]
)
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample6.py -v
6.
test1 (__main__.TestImaginaryNumbers) ... ok
test2 (__main__.TestImaginaryNumbers) ... ok
test3 (__main__.TestImaginaryNumbers) ... ok
----------------------------------------------------------------------
Ran 3 tests in 0.350s
OK
%
0 コメント:
コメントを投稿