ShaoHui
ShaoHui

Reputation: 3

Integrate with scipy

I want to integrate x**(-2/3)*(x-1)**(1/3) from 0~1, I had changed variables and use Simpson rule to solve it before,and now I want to try some quicker methods.

my code:

x1 = lambda x: x**(-2/3)*(x-1)**(1/3)
integrate.quad(x1,0,1)

Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/scipy/integrate/quadpack.py", line 281, in quad
    retval = _quad(func,a,b,args,full_output,epsabs,epsrel,limit,points)
  File "/usr/lib/python3/dist-packages/scipy/integrate/quadpack.py", line 345, in _quad
    return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
quadpack.error: Supplied function does not return a valid float.

How can I solve it?

Upvotes: 0

Views: 1435

Answers (1)

Anders
Anders

Reputation: 46

Even though the heading says Integrate with numpy, I suppose you mean scipy.. Your problem is that you have complex numbers in your function. For example, the part (x-1)**(1/3) becomes complex for x in [0, 1), but scipy.integrate.quad does not handle complex numbers. See e.g. Use scipy.integrate.quad to integrate complex numbers for more information.

Upvotes: 3

Related Questions