scipy: BUG: dblquad and args kwarg

Describe your issue.

There is a bug with scipy.dblquad that seems to be involved with using the args kwarg. The example below is the integral of a 2D Normal distribution, which should be unity. I am using the args kwarg to pass the coords of the center of the Normal. Note that the boundary of the integral is also using the same variable that are passed in args (although I don’t know why that might matter).

Reproducing Code Example

< import numpy as np; from scipy.integrate import dblquad
< sig = 1.3; x0=5.; y0=-3.;
< g = lambda x,y,xc,yc : (1/(2*np.pi*sig*sig))*np.exp(- ((x-xc)**2 + (y-yc)**2)/(2*sig*sig) )
< print([g(x0,y0,x0,y0), g(x0+1,y0+1,x0,y0)])
[0.09417452253958304, 0.05211400420209555]
< print([g(x0,y0,x0-5*sig,y0), g(x0+5*sig,y0,x0,y0)])
[3.509557831511321e-07, 3.509557831511321e-07]

< dblquad(g,x0-5*sig,x0+5*sig,y0-5*sig,y0+5*sig,args=(x0,y0))
> (0.015445922091068943, 6.2668582074865746e-09)
this answer is not close enough to unity for my taste.

Error message

no error message, just the wrong answer!

SciPy/NumPy/Python version information

np 1.16.2 scipy 1.2.1

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 19 (12 by maintainers)

Most upvoted comments

I was missing that cov should have been np.eye(2) * sig**2 instead of np.eye(2) * sig before. Not sure what is going wrong with the plot @tupui but the function is OK aside from the argument order.