## 2020年2月8日土曜日

### 数学 - Python - 代数学 - 1次方程式, 2次方程式 - 2次方程式 - 解、因数分解

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

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

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

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

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

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

7. $\begin{array}{l}{x}^{2}-9x+20=3{x}^{2}-9x+6-4\\ 2{x}^{2}-18=0\\ {x}^{2}-9=0\\ x=±3\end{array}$

8. $\begin{array}{l}\left(x-11a\right)\left(x+4a\right)=0\\ x=-4a,12a\end{array}$

9. $\begin{array}{l}{\left(x+2a\right)}^{2}=0\\ x=-2a\end{array}$

10. $\begin{array}{l}{x}^{2}-2bx-\left(a+b\right)\left(a-b\right)=0\\ \left(x-\left(a+b\right)\right)\left(x+\left(a-b\right)\right)=0\\ x=±a-b\end{array}$

コード

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

print('9.')

class MyTestCase(TestCase):
def test(self):
x, a, b = symbols('x, a, b', real=True)
eqs = [x ** 2 + 9 * x + 20,
x ** 2 - 4 * (x + 3),
-x ** 2 - 3 * x,
4 * x ** 2 - 25,
4 * x ** 2 - 12 * x + 9,
14 * x ** 2 - 31 * x - 10,
(x - 4) * (x - 5) - (3 * (x - 1) * (x - 2) - 4),
x ** 2 - 7 * a * x - 44 * a * 2,
x ** 2 + 4 * a * x + 4 * a ** 2,
x ** 2 - 2 * b * x - (a ** 2 - b ** 2)]
egg = [{-5, -4},
{-2, 6},
{-3, 0},
{-Rational(15, 2), Rational(15, 2)},
{Rational(3, 2)},
{-Rational(2, 7), Rational(5, 2)},
{-3, 3},
{-4 * a, 12 * a},
{-2 * a},
{a - b, -a - b}]
for eq, s in zip(eqs, egg):
self.assertTrue(solveset(eq, x), s)

if __name__ == "__main__":
main()


% ./sample9.py -v
9.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.295s

OK
%