2020年5月26日火曜日

学習環境

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


  1. 第2象限を通るのは

    1 , 3 , 4 , 5

    第3象限を通るのは

    1 , 2 , 4 , 6

コード

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

print('5, 6.')
a, b, x = symbols('a, b, x')
f = a * x + b
g1 = f.subs({a: 1})
g2 = f.subs({a: -1})
h1 = f.subs({b: 1})
h2 = f.subs({b: -1})

p = plot(*[l.subs({c: n})
           for l, c in [(g1, b), (h1, a), (g2, b), (h2, a)]
           for n in range(-1, 2)],
         (x, -5, 5),
         ylim=(-5, 5),
         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('sample5.png')

if __name__ == "__main__":
    main()

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

% ./sample5.py
5, 6.
/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)

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK
%

0 コメント:

コメントを投稿