2019年4月18日木曜日

学習環境

数学読本〈2〉簡単な関数/平面図形と式/指数関数・対数関数/三角関数 (松坂 和夫(著)、岩波書店)の第5章(関連しながら変化する世界 - 簡単な関数)、5.2(2次関数)、2次関数の最大・最小の問13の解答を求めてみる。



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

    2. y = - 2 x + 1 2 + 7 - 1 < x 7

    3. y = 1 2 x - 3 2 + 3 2 3 2 y 6

コード

Python 3

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

print('13.')

x = symbols('x')
intervals = [(2, 4),
             (-3, 1),
             (0, 4)]
fs = [x ** 2 - 3 * x,
      -2 * x ** 2 - 4 * x + 5,
      x ** 2 / 2 - 3 * x + 6]
ys_min = [-2, -1, Rational(3, 2)]
ys_max = [4, 7, 6]
p = plot(*[(f, (x, a, b)) for f, (a, b) in zip(fs, intervals)],
         *[(y, (x, a, b)) for y, (a, b) in zip(ys_min, intervals)],
         *[(y, (x, a, b)) for y, (a, b) in zip(ys_max, intervals)],
         show=False,
         legend=False)

colors = ['red', 'green', 'blue', 'brown', 'orange',
          'purple', 'pink', 'skyblue', 'gray', 'yellow']
l = list(zip(p[:3], colors)) + \
    list(zip(p[3:6], colors)) + \
    list(zip(p[6:], colors))
for o, color in l:
    o.line_color = color

p.show()
p.save('sample13.png')

入出力結果(cmd(コマンドプロンプト)、Terminal、Jupyter(IPython))

C:\Users\...>py sample13.py
13.

C:\Users\...>

0 コメント:

コメントを投稿