0

When I evaluate the following function

def f(k,varvz,D,z): return np.exp(-(k*(np.sqrt(z**2 + D**2)-D)+(0.041-0.0094*k)*z**2)/varvz) def g(k,varvz,D): return integrate.quad(f,-np.inf,np.inf,args=(k,varvz,D)) a,err= g(1.24,9.61,1.8) print a 

I get infand the following error message

inf c:\users\user1\appdata\local\temp\tmp5iuiuo.py:11: RuntimeWarning: overflow encountered in exp return np.exp(-(k*(np.sqrt(z**2 + D**2)-D)+(0.041-0.0094*k)*z**2)/varvz) 

But if I change the order of arguments in the definition of f

def f(z,k,varvz,D): return np.exp(-(k*(np.sqrt(z**2 + D**2)-D)+(0.041-0.0094*k)*z**2)/varvz) def g(k,varvz,D): return integrate.quad(f,-np.inf,np.inf,args=(k,varvz,D)) a,err= g(1.24,9.61,1.8) print a 

I get the desired result 14.5716742277

Why is this so?

Thanks

2
  • Shouldn't you also change args=(k,varvz,D)? Commented Dec 8, 2015 at 9:36
  • I want to integrate wrt z. k,D,varvz are parameters. Commented Dec 8, 2015 at 9:40

1 Answer 1

3

Your function to integrate (f) needs to be passed the axis to integrate along as the first argument. This is only true of your second definition. See the docs:

func : function

A Python function or method to integrate. If func takes many arguments, it is integrated along the axis corresponding to the first argument. 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.