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