2020年5月7日木曜日

学習環境

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



    1. {3x2+6y2=33x2-4y2=4310y2=-40y2=-4y=±2ix2=1-2y2=1+8=9x=±3x=±3,y=±2i

      (複号任意)


    2. {2x2+2xy+4y2=1482x2+2xy+y2=733y2=75y2=25y=±5x2±5x+50=74x2±5x-24=0x±8x3=0x=±3,8y=±5

      (複号同順)


    3. x3+y3=18x+yx2-xy+y2=18x2-xy+y2=9x2-x2-x+2-x2-9=0x2-2x+x2+4-4x+x2-9=03x2-6x-5=0x=3±9+153=3±263y=-3±263+2=3263

      (複号同順)

      y2=x2-13x4-x2-132+65=0x4-x4+26x2-169+65=026x2-104=0x2=4x=±2y2=4-13=-9y=±3i

      (複号 任意)

コード

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

コメントを投稿