Scipy如何在没有警告的情况下将其集成到自定义函数中?

时间:2018-09-07 14:07:20

标签: 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/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)

如何解决此问题? (集成警告)

提前谢谢!

0 个答案:

没有答案