学習環境
- Surface
- Windows 10 Pro (OS)
- Nebo(Windows アプリ)
- iPad
- MyScript Nebo - MyScript(iPad アプリ(iOS))
- 参考書籍
代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第5章(連立方程式と高次方程式) 、問8の解答を求めてみる。
コード
#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, solveset, I, Rational, sqrt
print('8.')
class TestEquations(TestCase):
def test(self):
x = symbols('x')
eqs = [2 * x ** 3 - 4 * x ** 2 - 3 * x + 6,
(x - 1) * (x - 2) * (x - 3) - 24,
5 * x ** 3 - 12 * x ** 2 + x + 6,
x ** 4 + 8 * x ** 3 + 9 * x ** 2 - 8 * x - 10,
4 * x ** 4 + 11 * x ** 2 - 3,
x ** 4 - 5 * x ** 3 + 5 * x ** 2 - 3 * x + 18,
(x ** 2 - 5 * x - 2) * (x ** 2 - 5 * x - 4) - 63,
x ** 3 + (x + 1) ** 3 + (x + 2) ** 3 - (x + 3) ** 3]
xss = [(2, -sqrt(6) / 2, sqrt(6) / 2),
(5, (1 - sqrt(23) * I) / 2, (1 + sqrt(23) * I) / 2),
(-Rational(3, 5), 1, 2),
(-1, 1, -4 - sqrt(6), -4 + sqrt(6)),
(-Rational(1, 2), Rational(1, 2), -sqrt(3) * I, sqrt(3) * I),
(3, (-1 - sqrt(7) * I) / 2, (-1 + sqrt(7) * I) / 2),
((5 - sqrt(5)) / 2, (5 + sqrt(5)) / 2,
(5 - sqrt(69)) / 2, (5 + sqrt(69)) / 2),
(3, (-3 - sqrt(3) * I) / 2, (-3 + sqrt(3) * I) / 2)]
for i, (eq, xs) in enumerate(zip(eqs, xss), 1):
print(f'({i})')
self.assertEqual(solveset(eq), set(xs))
if __name__ == "__main__":
main()
入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))
% ./sample8.py -v
8.
test (__main__.TestEquations) ... (1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
ok
----------------------------------------------------------------------
Ran 1 test in 0.371s
OK
%
0 コメント:
コメントを投稿