2020年6月3日水曜日

学習環境

代数への出発 (新装版 数学入門シリーズ) (松坂 和夫(著)、岩波書店)の第6章(1次方程式、2次方程式)、5(2次関数の最大と最小)の問16の解答を求めてみる。



    1. 2 < x < 4 y = x 2 - 3 x = x - 3 2 2 - 9 4

      よって値域は

      2 2 - 3 · 2 = - 2 < y < 4 2 - 3 · 4 = 4 - 2 < y < 4

    2. y = 2 x 2 + 2 x + 5 = 2 x + 1 2 + 3 - 3 < x < 1 3 y < 11

    3. y = - 1 2 x 2 - 6 x + 6 = - 1 2 x - 3 2 + 9 2 + 6 = - 1 2 x - 3 2 + 21 2 0 x < 4 6 y 21 2

コード

#!/usr/bin/env python3
from sympy import symbols, plot, Rational

print('16.')
x = symbols('x')
ys = [x ** 2 - 3 * x,
      2 * x ** 2 + 4 * x + 5,
      6 + 3 * x - x ** 2 / 2]
maxs = [4, 11, Rational(21, 2)]
mins = [-2, 3, 6]
intervals = [(x, a, b) for a, b in [(2, 4),
                                    (-3, 1),
                                    (0, 4)]]
for i, (y, mi, ma, interval) in enumerate(zip(ys, mins, maxs, intervals), 1):
    p = plot(y, mi, ma,
             interval,
             ylim=(min(mins), max(maxs)),
             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(f'sample16_{i}.png')

p.show()

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

% ./sample16.py 
16.
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/sympy/plotting/plot.py:1065: MatplotlibDeprecationWarning: 
The set_smart_bounds function was deprecated in Matplotlib 3.2 and will be removed two minor releases later.
  self.ax[i].spines['left'].set_smart_bounds(True)
/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/sympy/plotting/plot.py:1066: MatplotlibDeprecationWarning: 
The set_smart_bounds function was deprecated in Matplotlib 3.2 and will be removed two minor releases later.
  self.ax[i].spines['bottom'].set_smart_bounds(False)
%

0 コメント:

コメントを投稿