2020年2月9日日曜日

学習環境

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



    1. x = 5 ± 25 + 96 12 = 5 ± 121 12 = 5 ± 11 12 = - 1 2 , 4 3

    2. x = - 2 ± 2 2 + 4 · 4 2 = - 1 ± 1 + 4 = - 1 ± 5

    3. x = - 8 ± 8 2 + 4 · 16 2 = - 4 ± 16 + 16 = - 4 ± 4 2

    4. x = - 17 ± 1 7 2 - 24 · 12 2 · 6 = - 17 ± 1 12 = - 3 2 , - 4 3

    5. x = 11 ± 121 - 76 2 = 11 ± 45 2 = 11 ± 3 5 2

    6. x = 4 ± 4 2 + 4 · 6 2 · 3 = 2 ± 4 + 6 3 = 2 ± 10 3

    7. 25 x 2 - 10 x + 1 = 0 x = 10 ± 4 · 5 2 - 4 · 25 2 · 25 = 2 25 = 1 5

    8. x = 22 ± 2 2 · 1 1 2 - 4 · 49 2 = 11 ± 121 - 49 = 11 ± 72 = 11 ± 6 2

    9. x = - 7 ± 49 + 4 · 18 2 · 3 2 = - 7 ± 49 + 72 6 2 = - 7 ± 121 6 2 = - 7 ± 11 6 2 = - 3 2 , 2 3 2 = - 3 2 , 2 3

    10. x = 2 · 7 3 ± 2 2 · 7 2 · 3 - 4 · 26 2 · 2 = 7 3 ± 147 - 26 2 = 7 3 ± 121 2 = 7 3 ± 11 2

コード

#!/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 コメント:

コメントを投稿