## 2020年4月12日日曜日

### 数学 - Python - 代数学 - 連立方程式と高次方程式 - 連立2次方程式 - 連立2元2次方程式、未知数、解

1. $\begin{array}{l}{x}^{2}+{\left(x+1\right)}^{2}=13\\ 2{x}^{2}+2x-12=0\\ {x}^{2}+x-6=0\\ \left(x+3\right)\left(x-2\right)=0\\ x=-3,2\end{array}$

よって解は、

$\begin{array}{l}\left\{\begin{array}{l}x=-3\\ y=-2\end{array}\\ \left\{\begin{array}{l}x=2\\ y=3\end{array}\end{array}$

2. $\begin{array}{l}y=-x-5\\ x\left(-x-5\right)=6\\ {x}^{2}+5x+6=0\\ \left(x+2\right)\left(x+3\right)=0\\ \left\{\begin{array}{l}x=-2\\ y=-3\end{array}\\ \left\{\begin{array}{l}x=-3\\ y=-2\end{array}\end{array}$

3. $\begin{array}{l}y=5-x\\ {x}^{2}+x\left(5-x\right)+{\left(5-x\right)}^{2}=21\\ {x}^{2}-5x+4=0\\ \left(x-1\right)\left(x-4\right)=0\\ \left\{\begin{array}{l}x=1\\ y=4\end{array}\\ \left\{\begin{array}{l}x=4\\ y=1\end{array}\end{array}$

4. $\begin{array}{l}y=x-8\\ x\left(x-8\right)=-15\\ {x}^{2}-8x+15=0\\ \left(x-3\right)\left(x-5\right)=0\\ \left\{\begin{array}{l}x=3\\ y=-5\end{array}\\ \left\{\begin{array}{l}x=5\\ y=-3\end{array}\end{array}$

5. $\begin{array}{l}{\left(2x-1\right)}^{2}-{x}^{2}=5\\ 3{x}^{2}-4x-4=0\\ \left(x-2\right)\left(3x+2\right)=0\\ \left\{\begin{array}{l}x=-\frac{2}{3}\\ y=-\frac{7}{3}\end{array}\\ \left\{\begin{array}{l}x=2\\ y=3\end{array}\end{array}$

6. $\begin{array}{l}y=\frac{5-3x}{4}\\ 4{x}^{2}+x·\frac{5-3x}{4}-3·{\left(\frac{5-3x}{4}\right)}^{2}=0\\ 64{x}^{2}+20x-12{x}^{2}-3\left(25-30x+9{x}^{2}\right)=0\\ 25{x}^{2}+110x-75=0\\ 5{x}^{2}+22x-15=0\\ \left(x+5\right)\left(5x-3\right)=0\\ \left\{\begin{array}{l}x=-5\\ y=5\end{array}\\ \left\{\begin{array}{l}x=\frac{3}{5}\\ y=\frac{4}{5}\end{array}\end{array}$

7. $\begin{array}{l}\left(x-2y\right)\left(x-3y\right)=0\\ x=2y\\ 4{y}^{2}+2{y}^{2}+2{y}^{2}=56\\ {y}^{2}=7\\ y=±\sqrt{7}\\ x=3y\\ 9{y}^{2}+3{y}^{2}+2{y}^{2}=56\\ {y}^{2}=4\\ y=±2\\ \left\{\begin{array}{l}x=-2\sqrt{7}\\ y=-\sqrt{7}\end{array}\\ \left\{\begin{array}{l}x=2\sqrt{7}\\ y=\sqrt{7}\end{array}\\ \left\{\begin{array}{l}x=-6\\ y=-2\end{array}\\ \left\{\begin{array}{l}x=6\\ y=2\end{array}\end{array}$

8. $\begin{array}{l}\left(x-2y\right)\left(x-18y\right)=0\\ x=2y\\ 4{y}^{2}-4{y}^{2}+6{y}^{2}=6\\ y=±1\\ x=18y\\ 1{8}^{2}{y}^{2}-2·18·{y}^{2}+6{y}^{2}=6\\ 3·18{y}^{2}-2·3{y}^{2}+{y}^{2}=1\\ {y}^{2}=\frac{1}{49}\\ y=±\frac{1}{7}\\ \left\{\begin{array}{l}x=-2\\ y=-1\end{array}\\ \left\{\begin{array}{l}x=2\\ y=1\end{array}\\ \left\{\begin{array}{l}x=-\frac{18}{7}\\ y=-\frac{1}{7}\end{array}\\ \left\{\begin{array}{l}x=\frac{18}{7}\\ y=\frac{1}{7}\end{array}\end{array}$

9. $\begin{array}{l}9xy+27{y}^{2}=12\\ 9xy+27{y}^{2}={x}^{2}+3xy\\ {x}^{2}-6xy-27{y}^{2}=0\\ \left(x-9y\right)\left(x+3y\right)=0\\ x=9y\\ 81{y}^{2}+27{y}^{2}=12\\ {y}^{2}=\frac{12}{108}=\frac{1}{9}\\ y=±\frac{1}{3}\\ x=-3y\\ 9{y}^{2}-9{y}^{2}\ne 12\\ \left\{\begin{array}{l}x=-3\\ y=-\frac{1}{3}\end{array}\\ \left\{\begin{array}{l}x=3\\ y=\frac{1}{3}\end{array}\end{array}$

10. $\begin{array}{l}\left\{\begin{array}{l}60xy+48x-72y-60=0\\ 60xy+45x-70y-55=0\end{array}\\ 3x-2y-5=0\\ x=\frac{2y+5}{3}\\ 8{y}^{2}+20y+6y+15-14y-11=0\\ 8{y}^{2}+12y+4=0\\ 2{y}^{2}+3y+1=0\\ \left(y+1\right)\left(2y+1\right)=0\\ \left\{\begin{array}{l}x=1\\ y=-1\end{array}\\ \left\{\begin{array}{l}x=\frac{4}{3}\\ y=-\frac{1}{2}\end{array}\end{array}$

11. $\begin{array}{l}2xy-x-y=xy-1\\ xy-x-y+1=0\\ \left(x-1\right)y-\left(x-1\right)=0\\ \left(x-1\right)\left(y-1\right)=0\\ x=1\\ 1+{y}^{2}=5\left(y-1\right)\\ {y}^{2}-5y+6=0\\ \left(y-2\right)\left(y-3\right)=0\\ y=2,3\\ y=1\\ x=2,3\\ \left\{\begin{array}{l}x=1\\ y=2\end{array}\\ \left\{\begin{array}{l}x=1\\ y=3\end{array}\\ \left\{\begin{array}{l}x=2\\ y=1\end{array}\\ \left\{\begin{array}{l}x=3\\ y=1\end{array}\end{array}$

コード

#!/usr/bin/env python3
from unittest import TestCase, main
from sympy import symbols, solve, Rational, sqrt

print('9.')

x, y = symbols('x, y')

class TestEquations(TestCase):
def test1(self):
self.assertEqual(solve([x ** 2 + y ** 2 - 13, y - x - 1]),
[{x: -3, y: -2}, {x: 2, y: 3}])

def test2(self):
self.assertEqual(solve([x + y + 5, x * y - 6]),
[{x: -3, y: -2}, {x: -2, y: -3}])

def test3(self):
self.assertEqual(solve([x + y - 5,
x ** 2 + x * y + y ** 2 - 21]),
[{x: 1, y: 4}, {x: 4, y: 1}])

def test4(self):
self.assertEqual(solve([x - y - 8, x * y + 15]),
[{x: 3, y: -5}, {x: 5, y: -3}])

def test5(self):
self.assertEqual(solve([y - 2 * x + 1, y ** 2 - x ** 2 - 5]),
[{x: -Rational(2, 3), y: -Rational(7, 3)},
{x: 2, y: 3}])

def test6(self):
self.assertEqual(solve([3 * x + 4 * y - 5,
4 * x ** 2 + x * y - 3 * y ** 2]),
[{x: -5, y: 5},
{x: Rational(3, 5), y: Rational(4, 5)}])

def test7(self):
self.assertEqual(
sorted(solve([x ** 2 + x * y + 2 * y ** 2 - 56,
x ** 2 - 5 * x * y + 6 * y ** 2]),
key=lambda d: d[x]),
sorted([{x: -2 * sqrt(7), y: -sqrt(7)},
{x: 2 * sqrt(7), y: sqrt(7)},
{x: -6, y: -2},
{x: 6, y: 2}],
key=lambda d: d[x]))

def test8(self):
self.assertEqual(
sorted(solve([x ** 2 - 20 * x * y + 36 * y ** 2,
x ** 2 - 2 * x * y + 6 * y ** 2 - 6]),
key=lambda d: d[x]),
sorted([{x: -2, y: -1},
{x: 2, y: 1},
{x: -Rational(18, 7), y: -Rational(1, 7)},
{x: Rational(18, 7), y: Rational(1, 7)}],
key=lambda d: d[x]))

def test9(self):
self.assertEqual(
sorted(solve([x ** 2 + 3 * x * y - 12,
x * y + 3 * y ** 2 - Rational(4, 3)]),
key=lambda d: d[x]),
sorted([{x: -3, y: -Rational(1, 3)},
{x: 3, y: Rational(1, 3)}],
key=lambda d: d[x])
)

def test10(self):
self.assertEqual(
sorted(solve([5 * x * y + 4 * x - 6 * y - 5,
12 * x * y + 9 * x - 14 * y - 11]),
key=lambda d: d[x]),
sorted([{x: 1, y: -1},
{x: Rational(4, 3), y: -Rational(1, 2)}],
key=lambda d: d[x])
)

def test11(self):
self.assertEqual(
sorted(solve([x ** 2 + y ** 2 - 10 * x * y + 5 * (x + y),
x ** 2 + y ** 2 - 5 * (x * y - 1)]),
key=lambda d: d[x]),
sorted([{x: 1, y: 2},
{x: 1, y: 3},
{x: 2, y: 1},
{x: 3, y: 1}],
key=lambda d: d[x])
)

if __name__ == "__main__":
main()


% ./sample9.py -v
9.
test1 (__main__.TestEquations) ... ok
test10 (__main__.TestEquations) ... ok
test11 (__main__.TestEquations) ... ok
test2 (__main__.TestEquations) ... ok
test3 (__main__.TestEquations) ... ok
test4 (__main__.TestEquations) ... ok
test5 (__main__.TestEquations) ... ok
test6 (__main__.TestEquations) ... ok
test7 (__main__.TestEquations) ... ok
test8 (__main__.TestEquations) ... ok
test9 (__main__.TestEquations) ... ok

----------------------------------------------------------------------
Ran 11 tests in 0.519s

OK
%