简体   繁体   中英

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?

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 eg Use scipy.integrate.quad to integrate complex numbers for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM