2020年7月25日土曜日

学習環境

代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第7章(不等式)の練習問題5.の解答を求めてみる。


  1. x 2 + 2 x - 8 > - 5
    x 2 + 2 x - 3 > 0
    ( x + 3 ) ( x - 1 ) > 0
    x < - 3 , 1 < x
    x 2 + 2 x - 8 < 7
    x 2 + 2 x - 15 < 0
    ( x + 5 ) ( x - 3 ) < 0
    - 5 < x < 3

    よって、 不等式

    - 5 < x 2 + 2 x - 8 < 7

    の解は、

    - 5 < x < - 3 , 1 < x < 3

コード

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

print('5.')

y = x ** 2 + 2 * x - 8
pprint(reduce_inequalities([-5 < y, y < 7]))
p = plot((y, (x, -10, -5)),
         (y, (x, -5, -3)),
         (y, (x, -3, 1)),
         (y, (x, 1, 3)),
         (y, (x, 3, 10)),
         (-5, (x, -10, 10)),
         (7, (x, -10, 10)),
         ylim=(-10, 10),
         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.save('sample5.png')
p.show()

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

% ./sample5.py 
5.
(-5 < x ∧ x < -3) ∨ (1 < x ∧ x < 3)
%

0 コメント:

コメントを投稿