简体   繁体   English

与scipy整合

[英]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. 我想将x**(-2/3)*(x-1)**(1/3)x**(-2/3)*(x-1)**(1/3)进行积分,我曾经更改过变量并使用Simpson规则来解决它,现在我想尝试一些更快的方法。

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. 即使标题说与numpy集成,我想您的意思是scipy。您的问题是您的函数中有复数。 For example, the part (x-1)**(1/3) becomes complex for x in [0, 1), but scipy.integrate.quad does not handle complex numbers. 例如,对于[0,1 (x-1)**(1/3) ,部分(x-1)**(1/3)变得复数,但是scipy.integrate.quad不处理复数。 See eg Use scipy.integrate.quad to integrate complex numbers for more information. 有关更多信息,请参见例如, 使用scipy.integrate.quad来对复数进行积分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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