2020年5月7日木曜日

学習環境

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



    1. { 3 x 2 + 6 y 2 = 3 3 x 2 - 4 y 2 = 43 10 y 2 = - 40 y 2 = - 4 y = ± 2 i x 2 = 1 - 2 y 2 = 1 + 8 = 9 x = ± 3 x = ± 3 , y = ± 2 i

      (複号任意)


    2. { 2 x 2 + 2 x y + 4 y 2 = 148 2 x 2 + 2 x y + y 2 = 73 3 y 2 = 75 y 2 = 25 y = ± 5 x 2 ± 5 x + 50 = 74 x 2 ± 5 x - 24 = 0 x ± 8 x 3 = 0 x = ± 3 , 8 y = ± 5

      (複号同順)


    3. x 3 + y 3 = 18 x + y x 2 - x y + y 2 = 18 x 2 - x y + y 2 = 9 x 2 - x 2 - x + 2 - x 2 - 9 = 0 x 2 - 2 x + x 2 + 4 - 4 x + x 2 - 9 = 0 3 x 2 - 6 x - 5 = 0 x = 3 ± 9 + 15 3 = 3 ± 2 6 3 y = - 3 ± 2 6 3 + 2 = 3 2 6 3

      (複号同順)

      y 2 = x 2 - 13 x 4 - x 2 - 13 2 + 65 = 0 x 4 - x 4 + 26 x 2 - 169 + 65 = 0 26 x 2 - 104 = 0 x 2 = 4 x = ± 2 y 2 = 4 - 13 = - 9 y = ± 3 i

      (複号 任意)

コード

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

コメントを投稿