我不断收到类型错误,但我无法找出导致问题的原因。 我的代码是..
#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/