2020年5月30日土曜日

学習環境

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


  1. x = 0 , y = - 3 2
    1 2 x 2 + x - 3 2 = 0 x 2 + 2 x - 3 = 0 x + 3 x - 1 = 0 x = - 3 , 1 - 3 , 0 , 1 , 0


    1. y = 1 2 x 2 + 4 x = 1 2 x + 2 2 - 2

      よって軸の方程式は

      x = - 2

      頂点の座標は

      - 2 , - 2

    2. y = - x 2 - 2 x - 3 = - x - 1 2 - 2 x = 1 1 , - 2

    3. y = x - 2 2 - 1 x = 2 2 , - 1

    4. y = - 2 x 2 - 3 2 + 2 = - 2 x - 3 4 2 + 9 8 + 2 = - 2 x - 3 4 2 + 25 8 x = 3 4 3 4 , 25 8

      各2次関数のグラフ。

コード

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

print('11, 12.')
x = symbols('x')
ys = [x ** 2 / 2 + 2 * x,
      -x ** 2 + 2 * x - 3,
      x ** 2 - 4 * x + 3,
      -2 * x ** 2 + 3 * x + 2]


class Test(TestCase):
    def test10(self):
        y = x ** 2 / 2 + x - Rational(3, 2)
        self.assertEqual(y.subs({x: 0}), -Rational(3, 2))
        for x0 in [-3, 1]:
            self.assertEqual(y.subs({x: x0}), 0)


p = plot(*ys,
         (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('sample11.png')

if __name__ == "__main__":
    main()

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

% ./sample11.py -v
11, 12.
/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)
test10 (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.002s

OK
5

0 コメント:

コメントを投稿