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