scipy quad uses only 1 subdivision and gives wrong result

后端 未结 1 424
自闭症患者
自闭症患者 2021-01-22 09:27

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         


        
1条回答
  •  野的像风
    2021-01-22 10:09

    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
    

    0 讨论(0)
提交回复
热议问题