TypeError:无法将表达式转换为浮点型

TypeError:无法将表达式转换为浮点型,第1张

TypeError:无法将表达式转换为浮点

似乎您正在混合名称空间,因为您正在使用

from ... import *
。您想使用,
sympy.exp()
代码使用
math.exp()
。好的做法是将名称空间分隔开,即永远不要使用
from ... import*
-乍看起来似乎要键入更多内容,但最终会产生更清晰易懂的代码。尝试:

import sympy as syimport sympy.physics.units as unitsdef planck_law(wavelength,temperature):     """Planck's Law evaluation at a single wavelength and temperature """        T=temperature     f=units.c/wavelength     h=units.planck     k=units.boltzmann     U=2*h/(units.c**3)*(f**3)/(sy.exp(h*f/(k*T))-1)     return U.evalf()# Test:print(planck_law(640e-9*units.m, 500*units.K))# Result: 1.503553603007e-34*kg/(m*s)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5655126.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存