## 2019年2月5日火曜日

### 数学 - Python - 大小関係を見る - 不等式 – 不等式の解法 – 2次不等式(係数、定数、実数解、虚数解個数、判別式)

1. $\begin{array}{}D\\ ={\left(k+3\right)}^{2}-4\\ {\left(k+3\right)}^{2}>4\\ {k}^{2}+6k+5>0\\ \left(k+1\right)\left(k+5\right)>0\\ k<-5,-1

2. $\begin{array}{}\frac{D}{4}\\ ={\left(k-1\right)}^{2}-4k\\ ={k}^{2}-6k+1\ge 0\\ k=3±\sqrt{9-1}\\ =3±2\sqrt{2}\\ k\le 3-2\sqrt{2},3+2\sqrt{2}\le k\end{array}$

3. $\begin{array}{}\frac{D}{4}\\ ={\left(2k+1\right)}^{2}+\left({k}^{2}-1\right)\\ =4{k}^{2}+4k+1+{k}^{2}-1\\ =5{k}^{2}+4k\\ =k\left(5k+4\right)\\ <0\\ -\frac{4}{5}

コード

Python 3

#!/usr/bin/env python3
from sympy import pprint, symbols, plot
from sympy.solvers.inequalities import reduce_inequalities

print('12.')

def d(a, b, c):
return b ** 2 - 4 * a * c

k, x = symbols('k, x')
ts = [d(1, k + 3, 1) > 0,
d(1, -2 * (k - 1), 4 * k) >= 0,
d(1, 2 * (2 * k + 1), - (k ** 2 - 1)) < 0]

for i, t in enumerate(ts, 1):
print(f'({i})')
pprint(reduce_inequalities(t))

p = plot(*[x ** 2 + (k + 3) * x + 1 for k in [-6, -5, -4, -2, -1, 0]],
x=(-5, 5),
ylim=(-5, 5),
legend=True, show=False)
colors = ['red', 'green', 'blue', 'brown', 'orange', 'purple']

for i, _ in enumerate(p):
p[i].line_color = colors[i]

p.save('sample12.png')


$python3 sample12.py 12. (1) (-∞ < k ∧ k < -5) ∨ (-1 < k ∧ k < ∞) (2) (k ≤ -2⋅√2 + 3 ∧ -∞ < k) ∨ (2⋅√2 + 3 ≤ k ∧ k < ∞) (3) -4/5 < k ∧ k < 0$