我檢查了函數和參數,但找不到我的錯誤。如果你知道這裏發生了什麼,請發表評論。錯誤提供的函數不返回有效的浮點數
這裏是我的代碼:
from scipy.integrate import quad, dblquad
from sympy.mpmath import sin, cos, sqrt, pi
k0=0.1
def f(y, k):
return k**2 + (1 - k**2)*y**2
def p1(y,k):
return (1/f(y,k))*(f(y,k) - k**2 + (k**2)*sin(2*pi*sqrt(f(y,k)))/(2*pi*sqrt(f(y,k))))
def p2(y,k):
return (-1*k/(sqrt(1-y**2)*2*pi*f(y,k)))*(1 - cos(2*pi*sqrt(f(y,k))))
def p3(y,k):
return (k*y/(f(y,k)*sqrt(1-y**2)))*(f(y,k) - 1 + sin(2*pi*sqrt(f(y,k)))/(2*pi*sqrt(f(y,k))))
def q1(y,k):
return k*(1- y**2)*(1 - cos(2*pi*sqrt(f(y,k))))/f(y,k)
def q2(y,k):
return sqrt(1- y**2)*sin(2*pi*sqrt(f(y,k)))/sqrt(f(y,k))
def q3(y,k):
return y*sqrt(1-y**2)*(1 - cos(2*pi*sqrt(f(y,k))))/f(y,k)
r1 = lambda k: dblquad(lambda y,x: p2(x,k)*q3(y,k) - p3(x,k)*q2(y,k), -1, 1, lambda y: -1 , lambda y: y )
b = quad(r1, k0, 1)
print (b)
什麼行是錯誤的? – zeantsoi 2015-04-02 00:19:12
這是Python 2還是Python 3?你能發佈你得到的完整錯誤嗎? – KSFT 2015-04-02 00:20:31
python 3. retval = _quad(func,a,b,args,full_outputepsabs,epsrel,limit,points)line 281 return_quad_quadpack_qagse(func,a,b,args,full_output_epsabs,epsrel,limit)line 345 – 2015-04-02 00:46:52