## 2020年3月17日火曜日

### 数学 - Python - 代数学 - 1次方程式, 2次方程式 - 2次式、完全平方式、多項式、判別式、重解

1. $\begin{array}{l}D\\ ={\left(m+3\right)}^{2}-4m\left(m-3\right)\\ ={m}^{2}+6m+9-4{m}^{2}+12m\\ =-3{m}^{2}+18m+9\\ -3{m}^{2}+18m+9=0\\ {m}^{2}-6m-3=0\\ m=3±\sqrt{9+3}\\ =3±2\sqrt{3}\end{array}$

コード

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

print('11.')

x, m = symbols('x, m')
f = m * x ** 2 + (m + 3) * x + (m - 3)
fs = [f.subs({m: 3 + sign * 2 * sqrt(3)}) for sign in [-1, 1]]

class MyTestCase(TestCase):
def test(self):
for f in fs:
xs = solve(f, x)
self.assertEqual(len(xs), 1)

p = plot(*fs,
(x, -5, 5),
ylim=(-5, 5),
legend=True,
show=False)

colors = ['red', 'green', 'blue', 'brown', 'orange',
'purple', 'pink', 'gray', 'skyblue', 'yellow']

for o, color in zip(p, colors):
o.line_color = color

p.show()
p.save(f'sample11.png')

if __name__ == "__main__":
main()


% ./sample11.py -v
11.
test (__main__.MyTestCase) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.382s

OK
%