gpt4 book ai didi

python - 继续获取,类型错误 : a float is required

转载 作者:行者123 更新时间:2023-12-01 05:02:03 28 4
gpt4 key购买 nike

我不断收到类型错误,但我无法找出导致问题的原因。我的代码是..

#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.. 的代码

#Import modules
from math import sin, pi


#Define a function q that takes u as an argument

def q(u): #transmission function
d=20e-6 #separation of slits, units in meter
alpha=pi/d #

return (sin(alpha*u))**2 #the result of the transmission function

最佳答案

问题出在qnew的这个特定部分:

sqrt(q)

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

>>> sqrt(q)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: a float is required

q 是一个函数,因此您尝试取函数的平方根,这当然没有意义。我不确定您打算在其位置放置什么,但确定您需要修复的区域。

关于python - 继续获取,类型错误 : a float is required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25880268/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com