## 2018年12月10日月曜日

### 数学 – Python - 数学はここから始まる - 数 – 高次方程式 – 高次方程式の解法(因数定理、重解、3次式、4次式)

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

2. $\begin{array}{}{x}^{3}-4{x}^{2}-3x+18\\ =\left(x+2\right)\left({x}^{2}-6x+9\right)\\ =\left(x+2\right){\left(x-3\right)}^{2}\\ x=-2,3\end{array}$

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

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

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

6. $\begin{array}{}{x}^{4}-4{x}^{2}+16x+32\\ =\left(x+2\right)\left({x}^{3}-2{x}^{2}+16\right)\\ =\left(x+2\right)\left(x+2\right)\left({x}^{2}-4x+8\right)\\ {x}^{2}-4x+8=0\\ x=2±\sqrt{4-8}\\ =2±2i\\ x=-2,2\left(1±i\right)\end{array}$

コード(Emacs)

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, solve, sqrt, I, plot

print('27.')

x = symbols('x')
eqs = [x ** 3 - 4 * x + 3,
x ** 3 - 4 * x ** 2 - 3 * x + 18,
2 * x ** 3 - 4 * x ** 2 - 3 * x + 6,
2 * x ** 3 - x ** 2 + x + 1,
x ** 4 + 2 * x ** 3 + 3 * x ** 2 - 2 * x - 4,
x ** 4 - 4 * x ** 2 + 16 * x + 32]

for i, eq in enumerate(eqs, 1):
print(f'({i})')
pprint(solve(eq, x))
print()

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

for i, color in enumerate(colors):
p[i].line_color = color
p.save('sample27.png')


$./sample27.py 27. (1) ⎡ 1 √13 √13 1⎤ ⎢1, - ─ + ───, - ─── - ─⎥ ⎣ 2 2 2 2⎦ (2) [-2, 3] (3) ⎡ -√6 √6⎤ ⎢2, ────, ──⎥ ⎣ 2 2 ⎦ (4) ⎡ 1 √3⋅ⅈ 1 √3⋅ⅈ⎤ ⎢-1/2, ─ - ────, ─ + ────⎥ ⎣ 2 2 2 2 ⎦ (5) [-1, 1, -1 - √3⋅ⅈ, -1 + √3⋅ⅈ] (6) [-2, 2 - 2⋅ⅈ, 2 + 2⋅ⅈ]$