## 2020年5月28日木曜日

### 数学 - Python - 代数学 - 1次関数、2次関数 - 2次関数のグラフ - x軸、対称

1. x軸に対して対称な関係にある。

コード

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

print('8.')
a, x = symbols('a, x')
f = a * x ** 2
g = -a * x ** 2

class Test(TestCase):
def test(self):
self.assertEqual(f, -g)

p = plot(*[h.subs({a: a0})
for a0 in range(1, 6)
for h in [f, g]],
(x, -2, 2),
ylim=(-2, 2),
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('sample8.png')

if __name__ == "__main__":
main()


% ./sample8.py -v
8.
/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)
test (__main__.Test) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
%