我正在尝试整合你 - > exp(-u²/ 2)从-infinity到x。当我绘制函数时,在21左右突然下降并且在36左右下降到0,而它应该大致恒定到2.5。你怎么解释它?
import numpy as np
from scipy.integrate import quad
import matplotlib.pyplot as plt
def intExp(x):
return quad(lambda u: np.math.exp(-u*u/2),-np.Inf, x, full_output=0)
def plot(a,b, u, v,s):
plt.close()
t = np.arange(a,b,s)
plt.plot(t , map(intExp,t))
plt.axis([a, b, u, v])
plt.show()
plot(-10, 50, -1, 3, 1)
感谢您的帮助!
答案 0 :(得分:3)
与步宽有关。将epsabs
从其默认值更改为1e-9可以起作用:
import numpy as np
from scipy.integrate import quad
import matplotlib.pyplot as plt
def intExp(x):
return quad(lambda u: np.math.exp(-u*u/2),-np.Inf, x, full_output=0,epsabs=1e-9)
def plot(a,b, u, v,s):
plt.close()
t = np.arange(a,b,s)
plt.plot(t , map(intExp,t))
plt.axis([a, b, u, v])
plt.show()
plot(-10, 50, -1, 3, 1)