xの条件によって、F(x)が変化する関数をグラフにプロットしたい。
import matplotlib.pyplot as plt
from scipy.integrate import quad
import numpy as np
import math
x = np.linspace(-100, 100, 10000)
def A(x):
if x < 5.0:
return 2*x
elif 5.0 < x < 30:
return x**2
elif 30 < x:
return -3*x
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.grid()
ax.plot(x,A(x))
ax.set_xlim(-100, 100)
plt.show()
ValueError Traceback (most recent call last)
<ipython-input-3-b2084c7db5ab> in <module>
17 ax = fig.add_subplot(1,1,1)
18 ax.grid()
---> 19 ax.plot(x,A(x))
20 ax.set_xlim(-100, 100)
21 plt.show()
<ipython-input-3-b2084c7db5ab> in A(x)
7
8 def A(x):
----> 9 if x < 5.0:
10 return 2*x
11 elif 5.0 < x < 30:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()