Python 3.x 如何通过Scipy在没有警告的情况下集成自定义函数?

Python 3.x 如何通过Scipy在没有警告的情况下集成自定义函数?,python-3.x,scipy,Python 3.x,Scipy,我想通过Scipy集成我的自定义函数。但它显示了集成警告。这是我的密码: import numpy as np from numpy import sqrt, sin, cos, pi, exp import scipy.integrate as integrate import scipy.special as sp def fw(x): f0 = 1 thetaM = 70*(np.pi/180) return exp(-f0**(-2)*np.sin(x)**2

我想通过Scipy集成我的自定义函数。但它显示了集成警告。这是我的密码:

import numpy as np
from numpy import sqrt, sin, cos, pi, exp
import scipy.integrate as integrate
import scipy.special as sp


def fw(x):
    f0 = 1
    thetaM = 70*(np.pi/180)
    return exp(-f0**(-2)*np.sin(x)**2/np.sin(thetaM)**2)


def I00(q,z):
    k = 2*pi/(800 *10**(-9))
    intg = lambda x: fw(x)*sqrt(cos(x))*sin(x)*(1+cos(x))*sp.jv(0,k*q*sin(x))*exp(1j*k*z*cos(x))
    y, err = integrate.quad(intg, 0, 100)
    return y
它表明:

nan
C:\Users\Timothy\Anaconda3\lib\site-packages\scipy\integrate\quadpack.py:448: ComplexWarning: Casting complex values to real discards the imaginary part
  return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
D:/Tim/PythonScripts/ffcalc/integrals.py:29: RuntimeWarning: invalid value encountered in sqrt
  intg = lambda x: fw(x)*sqrt(cos(x))*sin(x)*(1+cos(x))*sp.jv(0,k*q*sin(x))*cos(k*z*cos(x))
C:\Users\Timothy\Anaconda3\lib\site-packages\scipy\integrate\quadpack.py:385: IntegrationWarning: The occurrence of roundoff error is detected, which prevents 
  the requested tolerance from being achieved.  The error may be 
  underestimated.
  warnings.warn(msg, IntegrationWarning)
如何解决此问题?(集成警告)


提前谢谢

显示触发错误的
I00(q,z)
的实际调用。您使用了
q
z
的哪些值?在被积函数中有表达式
exp(1j*k*z*cos(x))
scipy.integrate.quad
只能对实值函数进行积分。您应该验证您的被积函数在积分间隔内正确计算实值。q和z都是实值。请将该错误消息添加到问题中,以便阅读。函数中有
sqrt(cos(x))
。如果
x
的值为负值,则会引发错误。停止尝试调用
quad
,而是专注于确保被积函数的计算正确。“q和z都是实值”请给出实际值,以便有人可以尝试重现与您看到的完全相同的问题。