## 2020年4月29日水曜日

### 数学 - Python - 代数学 - 連立方程式と高次方程式 - 高次方程式と因数定理 - 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

print('23.')

x = symbols('x')

class TestQuarticEquation(TestCase):
def test1(self):
self.assertEqual(solveset(x ** 4 - 1),
{s * o
for s in [-1, 1]
for o in [1, I]})

def test2(self):
self.assertEqual(solveset(x ** 4 + 1),
{((s + t * I) / sqrt(2)).expand()
for s in [-1, 1]
for t in [-1, 1]})

def test3(self):
self.assertEqual(solveset(x ** 4 - 5 * x ** 2 + 6),
{s * sqrt(o)
for s in [-1, 1]
for o in [2, 3]})

p = plot(x ** 4, 1, -1, x ** 4 - 5 * x ** 2 + 6,
(x, -5, 5),
ylim=(-5, 5),
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('sample23.png')

if __name__ == "__main__":
main()


% ./sample23.py -v
23.
test1 (__main__.TestQuarticEquation) ... ok
test2 (__main__.TestQuarticEquation) ... ok
test3 (__main__.TestQuarticEquation) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.093s

OK
%