我是一个蟒蛇新手.我正在尝试使用python评估普朗克方程.我写了一个简单的程序.但是,当我给它输入时,给我一个错误.任何人都可以告诉我哪里出错了?这是程序和错误:
程序:
from __future__ import division
from sympy.physics.units import *
from math import *
import numpy
from scipy.interpolate import interp1d
#Planck's Law evaluation at a single wavelength and temperature
def planck_law(wavelength,temperature):
T=temperature
f=c/wavelength
h=planck
k=boltzmann
U=2*h/(c**3)*(f**3)/(exp(h*f/(k*T))-1)
return U.evalf()
Run Code Online (Sandbox Code Playgroud)
输入:我已将函数导入为'cp',输入如下
value = (cp.planck_law(400,2000))
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>`enter code here`
File "Camera_performance.py", line 14, in planck_law
U=2*h/(c**3)*(f**3)/(exp(h*f/(k*T))-1)
File "/usr/lib/python2.7/dist-packages/sympy/core/expr.py", line 221, in __float__
raise TypeError("can't convert expression to float")
TypeError: can't convert expression to …Run Code Online (Sandbox Code Playgroud)