2020年6月27日土曜日

学習環境

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


  1. - 2 x + 4 3 x - 5 x 9 5
    3 x - 5 < x + 7 x < 6

    よって、求める x の範囲は

    9 5 x < 6

コード

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

print('3.')

f = -2 * x + 4
g = 3 * x - 5
h = x + 7

pprint(reduce_inequalities([f <= g, g < h], x))

p = plot(f, g, h,
         (x, -10, 10),
         ylim=(-5, 15),
         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('sample3.png')

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

 % ./sample3.py
3.
9/5 ≤ x ∧ x < 6
%

0 コメント:

コメントを投稿