## 2020年6月26日金曜日

### 数学 - Python - 代数学 - 不等式 - 1次不等式 - 2つの不等式の解

1. $\begin{array}{l}2x-3<4x+5\\ x>-4\end{array}$
$\begin{array}{l}7x-5<3x+9\\ x<\frac{7}{2}\end{array}$

よって、

$-4

2. $\begin{array}{l}x\ge -3,x<2\\ -3\le x<2\end{array}$

3. $x>-1$
$\begin{array}{l}2x<3x+3\\ x>-3\end{array}$
$x>-1$

コード

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

print('2.')

exprs = [[2 * x - 3 < 4 * x + 5, 7 * x - 5 < 3 * x + 9],
[17 - 5 * x <= 50 + 6 * x, 5 * x + 7 < 3 * x + 11],
[-3 * x / 2 - 1 < Rational(1, 2), x < 3 * (x + 1) / 2]]

for i, expr in enumerate(exprs, 1):
print(f'({i})')
pprint(reduce_inequalities(expr, x))

p = plot(2 * x - 3,
4 * x + 5,
7 * x - 5,
3 * x + 9,
(x, -5, 5),
ylim=(-25, 25),
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('sample2.png')


% ./sample2.py
2.
(1)
-4 < x ∧ x < 7/2
(2)
-3 ≤ x ∧ x < 2
(3)
-1 < x ∧ x < ∞
%