Reputation: 49
I want to plot a function which has integrate.quad
in it. The function has true float value in the interval.
import matplotlib.pyplot as plt
import numpy as np
import scipy.integrate as integrate
def S(M):
s = integrate.quad(lambda k: np.exp(-k) * np.sin(2 * M), 0, 5)[0]
return s
M = np.arange(10, 20, 1)
plot = plt.plot(M, S(M))
plt.show()
But I receive this error:
error: Supplied function does not return a valid float.
I don't know the reason the function has correct float value and I specified the first term of quad output with [0]
.
Upvotes: 0
Views: 314
Reputation: 1484
S()
is unable to handle vector input. Try to replace the line with the plot()
by this:
plot = plt.plot(M, np.vectorize(S)(M))
Upvotes: 2