## 2020年5月12日火曜日

### 数学 - Python - 代数学 - 連立方程式と高次方程式 - 展開、因数分解、因数定理、解、複素数の範囲

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

2. $\begin{array}{l}\left({x}^{2}-3x+2\right)\left(x-3\right)=24\\ {x}^{3}-6{x}^{2}+11x-30=0\\ 125-150+55-30=0\\ \left(x-5\right)\left({x}^{2}-x+6\right)=0\\ x=\frac{1±\sqrt{1-24}}{2}=\frac{1±\sqrt{23}i}{2}\\ x=5,\frac{1±\sqrt{23}i}{2}\end{array}$

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

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

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

6. $\begin{array}{l}16-40+20-6+18\ne 0\\ 81-135+45-9+18=0\\ \left(x-3\right)\left({x}^{3}-2{x}^{2}-x-6\right)=0\\ 27-18-3-6=0\\ {\left(x-3\right)}^{2}\left({x}^{2}+x+2\right)=0\\ x=\frac{-1±\sqrt{1-8}}{2}=\frac{-1±\sqrt{7}i}{2}\\ x=3,\frac{-1±\sqrt{7}i}{2}\end{array}$

7. $\begin{array}{l}{\left({x}^{2}-5x\right)}^{2}-6\left({x}^{2}-5x\right)-55=0\\ \left({x}^{2}-5x-11\right)\left({x}^{2}-5x+5\right)=0\\ x=\frac{5±\sqrt{25+44}}{2},\frac{5±\sqrt{25-20}}{2}\\ =\frac{5±\sqrt{69}}{2},\frac{5±\sqrt{5}}{2}\end{array}$

8. $\begin{array}{l}{x}^{3}+{x}^{3}+3{x}^{2}+3x+1+{x}^{3}+6{x}^{2}+12x+8={x}^{3}+9{x}^{2}+27x+27\\ 2{x}^{3}-12x-18=0\\ {x}^{3}-6x-9=0\\ 27-18-9=0\\ \left(x-3\right)\left({x}^{2}+3x+3\right)=0\\ x=\frac{-3±\sqrt{9-12}}{2}=\frac{-3±\sqrt{3}i}{2}\\ x=3,\frac{-3±\sqrt{3}i}{2}\end{array}$

コード

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

print('8.')

class TestEquations(TestCase):
def test(self):
x = symbols('x')
eqs = [2 * x ** 3 - 4 * x ** 2 - 3 * x + 6,
(x - 1) * (x - 2) * (x - 3) - 24,
5 * x ** 3 - 12 * x ** 2 + x + 6,
x ** 4 + 8 * x ** 3 + 9 * x ** 2 - 8 * x - 10,
4 * x ** 4 + 11 * x ** 2 - 3,
x ** 4 - 5 * x ** 3 + 5 * x ** 2 - 3 * x + 18,
(x ** 2 - 5 * x - 2) * (x ** 2 - 5 * x - 4) - 63,
x ** 3 + (x + 1) ** 3 + (x + 2) ** 3 - (x + 3) ** 3]
xss = [(2, -sqrt(6) / 2, sqrt(6) / 2),
(5, (1 - sqrt(23) * I) / 2, (1 + sqrt(23) * I) / 2),
(-Rational(3, 5), 1, 2),
(-1, 1, -4 - sqrt(6), -4 + sqrt(6)),
(-Rational(1, 2), Rational(1, 2), -sqrt(3) * I, sqrt(3) * I),
(3, (-1 - sqrt(7) * I) / 2, (-1 + sqrt(7) * I) / 2),
((5 - sqrt(5)) / 2, (5 + sqrt(5)) / 2,
(5 - sqrt(69)) / 2, (5 + sqrt(69)) / 2),
(3, (-3 - sqrt(3) * I) / 2, (-3 + sqrt(3) * I) / 2)]
for i, (eq, xs) in enumerate(zip(eqs, xss), 1):
print(f'({i})')
self.assertEqual(solveset(eq), set(xs))

if __name__ == "__main__":
main()


% ./sample8.py -v
8.
test (__main__.TestEquations) ... (1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
ok

----------------------------------------------------------------------
Ran 1 test in 0.371s

OK
%