## 2020年7月28日火曜日

### 数学 - Python - 代数学 - 不等式 - 2つの2次方程式が実解をもつ場合、判別式

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

よって 2つの2 次方程式が実解をもつ k の範囲は

$k\le 2-2\sqrt{2}$

コード

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

print('8.')

d1 = 4 ** 2 - 4 * k
d2 = k ** 2 - 4 * (k + 1)

pprint(reduce_inequalities([d >= 0 for d in [d1, d2]]))

f = x ** 2 + 4 * x + k
g = x ** 2 + k * x + (k + 1)
ks = [-2 * sqrt(2), 2 - 2 * sqrt(2), 2, 2 + 2 * sqrt(2), 4]
p = plot(
*[f.subs({k: k0}) for k0 in ks],
*[g.subs({k: k0}) for k0 in ks],
(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.save('sample8.png')
p.show()


% ./sample8.py
8.
k ≤ 2 - 2⋅√2 ∧ -∞ < k
cartesian line: x**2 + 4*x - 2*sqrt(2) for x over (-10.0, 10.0) red
cartesian line: x**2 + 4*x - 2*sqrt(2) + 2 for x over (-10.0, 10.0) green
cartesian line: x**2 + 4*x + 2 for x over (-10.0, 10.0) blue
cartesian line: x**2 + 4*x + 2 + 2*sqrt(2) for x over (-10.0, 10.0) brown
cartesian line: x**2 + 4*x + 4 for x over (-10.0, 10.0) orange
cartesian line: x**2 - 2*sqrt(2)*x - 2*sqrt(2) + 1 for x over (-10.0, 10.0) purple
cartesian line: x**2 + x*(2 - 2*sqrt(2)) - 2*sqrt(2) + 3 for x over (-10.0, 10.0) pink
cartesian line: x**2 + 2*x + 3 for x over (-10.0, 10.0) gray
cartesian line: x**2 + x*(2 + 2*sqrt(2)) + 2*sqrt(2) + 3 for x over (-10.0, 10.0) skyblue
cartesian line: x**2 + 4*x + 5 for x over (-10.0, 10.0) yellow
%