Why does integrate.quad(lambda x: x*exp(-x**2/2)/s

2020-05-01 04:58发布

问题:

This function is positive from 0 to inf, why give larger than 1000 will yield to 0, not reasonable.

import scipy.integrate as integrate
from math import *

integrate.quad(lambda x: x*exp(-x**2/2)/sqrt(2*pi), 0.0, 1000)
Out[52]: 
(0.3989422804014328, 1.6471510195390376e-11)
integrate.quad(lambda x: x*exp(-x**2/2)/sqrt(2*pi), 0.0, 100000)
Out[54]: 
(0.0, 0.0)

回答1:

For x larger than approx. 39, exp(-x**2/2) gives 0.0. When the upper limit of integration is 100000, the fraction of the interval of integration where the function is nonzero is so small that the quad algorithm never sees it. As far as quad is concerned, the function is identically 0.