## 2020年5月1日金曜日

### 数学 - Python - 代数学 - 連立方程式と高次方程式 - 高次方程式と因数定理 - 3次方程式、4次方程式の解、因数定理の応用

1. $\begin{array}{l}{x}^{4}=1\\ {x}^{4}-1=0\\ \left({x}^{2}+1\right)\left({x}^{2}-1\right)=0\\ x=±1,±i\end{array}$

2. $\begin{array}{l}{x}^{4}+1=0\\ {\left({x}^{2}+1\right)}^{2}-2{x}^{2}=0\\ \left({x}^{2}+1-\sqrt{2}x\right)\left({x}^{2}+1+\sqrt{2}x\right)=0\\ {x}^{2}-\sqrt{2}x+1=0\\ {x}^{2}+\sqrt{2}x+1=0\\ x=\frac{±\sqrt{2}±\sqrt{2-4}}{2}\\ =\frac{±\sqrt{2}±\sqrt{2}i}{2}\\ =\frac{±1±i}{\sqrt{2}}\end{array}$

（複号任意）

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

コード

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

print('24.')

x = symbols('x', imag=True)
fs = [x ** 3 - 6 * x ** 2 - 5 * x + 2,
x ** 3 - 4 * x ** 2 - 3 * x + 18,
2 * x ** 3 + x ** 2 + x - 1,
x ** 4 + x ** 3 - 6 * x ** 2 + x + 3]
xss = [(-1, *[(7 + s * sqrt(41)) / 2 for s in [-1, 1]]),
(-2, 3),
(Rational(1, 2), *[(-1 + s * sqrt(3) * I) / 2 for s in [-1, 1]]),
(-3, 1, *[(1 + s * sqrt(5)) / 2 for s in [-1, 1]])]

class TestQuarticEquation(TestCase):
def test(self):
for i, (f, xs) in enumerate(zip(fs, xss), 1):
print(f'({i})')
self.assertEqual(solveset(f), set(xs))

p = plot(*fs,
(x, -10, 10),
ylim=(-10, 10),
legend=True,
show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange', 'pink']

for i, s in enumerate(p):
s.line_color = colors[i]

p.show()
p.save('sample24.png')

if __name__ == "__main__":
main()


% ./sample24.py -v
24.
test (__main__.TestQuarticEquation) ... (1)
(2)
(3)
(4)
ok

----------------------------------------------------------------------
Ran 1 test in 0.125s

OK
%