我正试图将u->exp(-u²/2(从无穷大积分到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)
谢谢你的帮助!
与步长有关。将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)