2020年6月1日月曜日

学習環境

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



    1. y=x2-4x+7=x-22+3

      よって

      x=2

      のとき最小となり、 その値は3。


    2. y=-x+32+14

      x が-3のとき最大値14。


    3. y=4x+322

      よって

      x=-32

      のとき最小値0。


    4. y=34x2+8x-12=34x+42-24

      x が-4のとき最小値-24。


    5. y=-32x2-43x=-32x-232+32232=-32x-232+23

    6. y=13x-32-12x-25=-16x2-32+25x-110=-16x2-1910x-110=-16x-19202+16·19202-110=-16x-19202+16·361400-110=-16x-19202+1212400

    7. y=ax2-bax=ax-b2a2-b24a

      よって

      x=-b2a

      のとき最小値

      -b24a

    8. y=ax2-x=ax-122-a4

コード

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

print('14.')
x = symbols('x')
ys = [x ** 2 - 4 * x + 7,
      4 * x ** 2 + 12 * x + 9,
      x * (4 - 3 * x) / 2]
ys0 = [3, 0, Rational(2, 3)]

p = plot(*ys, *ys0,
         (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.show()
p.save('sample14.png')

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

% ./sample14.py
14.
/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 コメント:

コメントを投稿