## 2020年5月7日木曜日

### 数学 - Python - 代数学 - 連立方程式と高次方程式 - 2元、3元、2次、3次、4次

1. $\begin{array}{l}\left\{\begin{array}{l}3{x}^{2}+6{y}^{2}=3\\ 3{x}^{2}-4{y}^{2}=43\end{array}\\ 10{y}^{2}=-40\\ {y}^{2}=-4\\ y=±2i\\ {x}^{2}\\ =1-2{y}^{2}\\ =1+8\\ =9\\ x=±3\\ x=±3,y=±2i\end{array}$

（複号任意）

2. $\begin{array}{l}\left\{\begin{array}{l}2{x}^{2}+2xy+4{y}^{2}=148\\ 2{x}^{2}+2xy+{y}^{2}=73\end{array}\\ 3{y}^{2}=75\\ {y}^{2}=25\\ y=±5\\ {x}^{2}±5x+50=74\\ {x}^{2}±5x-24=0\\ \left(x±8\right)\left(x\mp 3\right)=0\\ x=±3,\mp 8\\ y=±5\end{array}$

（複号同順）

3. $\begin{array}{l}{x}^{3}+{y}^{3}=18\\ \left(x+y\right)\left({x}^{2}-xy+{y}^{2}\right)=18\\ {x}^{2}-xy+{y}^{2}=9\\ {x}^{2}-x\left(2-x\right)+{\left(2-x\right)}^{2}-9=0\\ {x}^{2}-2x+{x}^{2}+4-4x+{x}^{2}-9=0\\ 3{x}^{2}-6x-5=0\\ x=\frac{3±\sqrt{9+15}}{3}\\ =\frac{3±2\sqrt{6}}{3}\\ y=-\frac{3±2\sqrt{6}}{3}+2\\ =\frac{3\mp 2\sqrt{6}}{3}\end{array}$

（複号同順）

$\begin{array}{l}{y}^{2}={x}^{2}-13\\ {x}^{4}-{\left({x}^{2}-13\right)}^{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=±3i\end{array}$

（複号 任意）

コード

#!/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()


% ./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
%