## 2020年7月4日土曜日

### 数学 - Python - 代数学 - 不等式 - 2次不等式 - 異なる実数解をもつ場合、係数、判別式

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

2. $\frac{D}{4}={\left(k-1\right)}^{2}-k>0$
${k}^{2}-3k+1>0$
${k}^{2}-3k+1=0$
$k=\frac{3±\sqrt{9-4}}{2}=\frac{3±\sqrt{5}}{2}$
$k<\frac{3-\sqrt{5}}{2},\frac{3+\sqrt{5}}{2}

コード

#!/usr/bin/env python3
from sympy import pprint, symbols, plot, sqrt, Rational
from sympy.solvers.inequalities import reduce_inequalities
from sympy.abc import k, x

print('10.')

f = x ** 2 - 3 * x - 10
g = x ** 2 - 2 * x - 40

for i, d in enumerate([(k + 3) ** 2 - 4, (k - 1) ** 2 - k], 1):
print(f'({i})')
pprint(reduce_inequalities([d > 0]))

p = plot(*[x ** 2 + (k + 3) * x + 1 for k in [-6, -5, -2, -1, 2]],
*[x ** 2 - 2 * (k - 1) * x + k for k in [(3 - sqrt(5)) / 2 - 1,
(3 - sqrt(5)) / 2,
Rational(3, 2),
(3 + sqrt(5)) / 2,
(3 + sqrt(5)) / 2 + 1]],
(x, -10, 10),
ylim=(-10, 10),
legend=False,
show=False)

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

for o, color in zip(p, colors):
o.line_color = color
print(o, color)
p.show()
p.save('sample10.png')


% ./sample10.py
10.
(1)
(-∞ < k ∧ k < -5) ∨ (-1 < k ∧ k < ∞)
(2)
⎛             3   √5⎞   ⎛        √5   3    ⎞
⎜-∞ < k ∧ k < ─ - ──⎟ ∨ ⎜k < ∞ ∧ ── + ─ < k⎟
⎝             2   2 ⎠   ⎝        2    2    ⎠
cartesian line: x**2 - 3*x + 1 for x over (-10.0, 10.0) red
cartesian line: x**2 - 2*x + 1 for x over (-10.0, 10.0) green
cartesian line: x**2 + x + 1 for x over (-10.0, 10.0) blue
cartesian line: x**2 + 2*x + 1 for x over (-10.0, 10.0) brown
cartesian line: x**2 + 5*x + 1 for x over (-10.0, 10.0) orange
cartesian line: x**2 - x*(-sqrt(5) - 1) - sqrt(5)/2 + 1/2 for x over (-10.0, 10.0) purple
cartesian line: x**2 - x*(1 - sqrt(5)) - sqrt(5)/2 + 3/2 for x over (-10.0, 10.0) pink
cartesian line: x**2 - x + 3/2 for x over (-10.0, 10.0) gray
cartesian line: x**2 - x*(1 + sqrt(5)) + sqrt(5)/2 + 3/2 for x over (-10.0, 10.0) skyblue
cartesian line: x**2 - x*(sqrt(5) + 3) + sqrt(5)/2 + 5/2 for x over (-10.0, 10.0) yellow
%