It seem like you are mixing namespaces, since your are using from ... import *
. You wanted to use sympy.exp()
but your code uses math.exp()
. It is good practice to keep the namespaces separated, i.e. never use from ... import *
- it might seem like more typing at first, but will produce much cleaner easier comprehensible code in the end.
Try:
import sympy as sy
import sympy.physics.units as units
def 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)