继续获取,类型错误:需要浮点

2024-10-01 09:21:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直收到输入错误,但我不知道是哪个引起了问题。 我的代码是。。在

#import modules needed
from math import sin, pi, sqrt
from cmath import exp
from lab2_q4b import q

#Define constants
lamda=500e-6 #wavelength of the incident light, units in meter
n=10 #number of slits in a dffraction grating
f=1.0 #focal length, units in meter
x=0.1 #width of the screen, units in meter

#Define a new function called qnew, which will be our integrand
def qnew(u):
    return sqrt(q)*exp(1j*2*pi*x*u/(lamda*f))

我运行这个它会给我错误。。在

这是q的代码。。在

^{pr2}$

Tags: ofthe代码infromimportmodules错误
2条回答

问题在于qnew的这一段:

sqrt(q)

在Isolation中运行这段代码将引发您看到的异常:

^{pr2}$

q是一个函数,所以你试图取函数的平方根,这当然没有意义。我不知道你想把它放在什么地方,但你需要修复的地方。在

我想你应该把它改成:

 return sqrt(q(u))*exp(1j*2*pi*x*u/(lamda*f))

相关问题 更多 >