## 2020年5月17日日曜日

### 数学 - Python - 代数学 - 連立方程式と高次方程式 - 整式、因数定理、因数分解、共通解

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

問題の3次方程式が解-1または2をもつためには、

$\begin{array}{l}-2-5+4+a=0\\ a=3\\ 16-20-8+a=0\\ a=12\end{array}$

a が3のとき、 3次方程式 の解は

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

a が12の場合、

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

コード

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

print('11.')

x, a, b = symbols('x, a, b')
eq1 = 2 * x ** 3 - 5 * x ** 2 - 4 * x + a
eq2 = x ** 2 - x - 2
xs = solveset(eq2)

class TestEquations(TestCase):
def test1(self):
self.assertEqual(xs, {-1, 2})

def test2(self):
self.assertEqual(solveset(eq1.subs({a: 3})),
{-1, Rational(1, 2), 3})

def test3(self):
self.assertEqual(solveset(eq1.subs({a: 12})),
{-Rational(3, 2), 2})

if __name__ == "__main__":
main()


% ./sample11.py -v
11.
test1 (__main__.TestEquations) ... ok
test2 (__main__.TestEquations) ... ok
test3 (__main__.TestEquations) ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.044s

OK
%