I want to use quad to get the mean of a Gaussian distribution. My first try and 2nd try gets different result. And the 2nd try of quad uses only 1 subdivision.
m
Because the limits of integration are so far out in the tails of the Gaussian, you've fooled quad
into thinking that the function is identically 0:
In [104]: f(-1000)
Out[104]: -0.0
In [105]: f(-500)
Out[105]: -0.0
In [106]: f(-80)
Out[106]: -0.0
In [107]: f(-50)
Out[107]: -6.2929842629835128e-141
You can fix this several ways, one of which is to add the argument points=[mu]
to the call to quad
:
In [110]: b = si.quad(f, -1001., 1001., full_output=True, points=[mu])
b
In [111]: b[0]
Out[111]: 1.0000000000000002