## 2018年12月31日月曜日

### 数学 – Python - 数学はここから始まる - 数 – 高次方程式 – 連立2次方程式(3元以上の連立2次方程式)

1. $\begin{array}{}y=-2x-1\\ x+4x+2+z=-4\\ z=-5x-6\\ {x}^{2}+{\left(-2x-1\right)}^{2}+{\left(-5x-6\right)}^{2}=29\\ {x}^{2}+4{x}^{2}+4x+1+25{x}^{2}+60x+36=29\\ 30{x}^{2}+64x+8=0\\ 15{x}^{2}+32x+4=0\\ \left(x+2\right)\left(15x+2\right)=0\\ x=-2,y=3,z=4\\ x=-\frac{2}{15}\\ y=\frac{4}{15}-1=-\frac{11}{15}\\ z=\frac{10}{15}-6=\frac{2}{3}-6=-\frac{16}{3}\end{array}$

2. $\begin{array}{}y=\frac{420}{x}\\ x+\frac{420}{x}+z=70\\ z=-x-\frac{420}{x}+70\\ {x}^{2}+{\left(\frac{420}{x}\right)}^{2}={\left(-x-\frac{420}{x}+70\right)}^{2}\\ {x}^{2}+{\left(\frac{420}{x}\right)}^{2}={\left(\frac{-{x}^{2}+70x-420}{x}\right)}^{2}\\ {x}^{4}+{\left(420\right)}^{2}={\left({x}^{2}-70x+420\right)}^{2}\\ {x}^{4}+{\left(420\right)}^{2}={\left({x}^{2}-70x\right)}^{2}+{\left(420\right)}^{2}+2·420\left({x}^{2}-70x\right)\\ {x}^{4}={x}^{4}-140{x}^{3}+4900{x}^{2}+840{x}^{2}-58800x\\ 140{x}^{3}-5740{x}^{2}+58800x=0\\ x\left({x}^{2}-41x+420\right)=0\\ x\left(x-20\right)\left(x-21\right)=0\\ x\ne 0\\ x=20\\ y=21\\ z=-20-21+70=29\\ x=21\\ y=20\\ z=-21-20+70=29\end{array}$

3. $\begin{array}{}{\left(x+y+z\right)}^{2}=16\\ x+y+z=±4\\ x=±\frac{3}{2}\\ y=\mp \frac{5}{2}\\ z=±5\end{array}$

（複号同順）

4. $\begin{array}{}zx=-2yz\\ -2yz-3xy=0\\ yz=-\frac{3}{2}xy\\ xy-6xy=10\\ xy=-2\\ yz=3\\ zx=-6\\ z=-\frac{6}{x}\\ y\left(-\frac{6}{x}\right)=3\\ y=-\frac{1}{2}x\\ x=\frac{4}{x}\\ {x}^{2}=4\\ x=±2\\ y=\mp 1\\ z=\mp 3\end{array}$

（複号同順）

コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, solve, sqrt
from sympy.plotting import plot3d

print('39.')

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

ts = [(2 * x + y - 1,
x - 2 * y + z + 4,
x ** 2 + y ** 2 + z ** 2 - 29),
(x + y + z - 70,
x * y - 420,
x ** 2 + y ** 2 - z ** 2),
(x * (x + y + z) - 6,
y * (x + y + z) + 10,
z * (x + y + z) - 20),
(2 * y * z + z * x,
z * x - 3 * x * y,
x * y + 4 * y * z - 10)]

for i, t in enumerate(ts, 1):
print(f'({i})')
pprint(solve(t, dict=True))
print()

p = plot3d(-x + 2 * y - 4,
sqrt(29 - x ** 2 + y ** 2),
-sqrt(29 - x ** 2 + y ** 2),
show=False)

p.save('sample39.png')


$./sample39.py 39. (1) [{x: -6/5, y: 17/5, z: 4}, {x: 2/3, y: -1/3, z: -16/3}] (2) [{x: 20, y: 21, z: 29}, {x: 21, y: 20, z: 29}] (3) [{x: -3/2, y: 5/2, z: -5}, {x: 3/2, y: -5/2, z: 5}] (4) [{x: -2, y: 1, z: 3}, {x: 2, y: -1, z: -3}]$