6
$\begingroup$

This code plots a 1000 point black body radiation curve in 0.7 seconds.

h = 6.62*10^-34
c = 2.99792458*10^8
k = 1.38064880*10^-23
T = 3000.
Isubν[ν_] := ((2 h ν^3)/c^2) 1/(E^((h ν)/(k T)) - 1)

Plot[Isubν[ν], {ν, 1*10^13, 1*10^15}, AxesOrigin -> Automatic, PlotPoints -> 1000,
     MaxRecursion -> 1]

However, using Quantities with units, the following code takes 19 seconds for just 200 points. What am I doing wrong?

h = Quantity[6.62*10^-34, "Joules"*"Seconds"]
c = Quantity[2.99792458*10^8, "Meters"/"Seconds"]
k = Quantity[1.38064880*10^-23, "Joules"/"Kelvins"]
T = Quantity[3000, "Kelvins"]

Isubν[ν_] := ((2 h (Quantity[ν, "Hertz"])^3)/c^2) 1/(E^((h (Quantity[ν, "Hertz"]))/(k T)) - 1)

Plot[Isubν[ν], {ν, 1.0*10^13, 1.0*10^15}, AxesOrigin -> {1.*10^13, 0.},
     PlotPoints -> 200, MaxRecursion -> 1]
$\endgroup$
4
  • 3
    $\begingroup$ Units are slow, I'm afraid. By the way, Planck's constant, the speed of light, and Boltzmann's constant are built in: Quantity[1, "PlanckConstant"], Quantity[1, "SpeedOfLight"] and Quantity[1, "BoltzmannConstant"]. See mathematica.stackexchange.com/questions/16446/… $\endgroup$ Commented Oct 28, 2015 at 7:38
  • $\begingroup$ As noted, these ones are on the slow side, unfortunately. Consider reformulating so that you are doing computations with natural units, or nondimensional quantities. (QuantityMagnitude[] is particularly useful.) There is also the new PlanckRadiationLaw[] function. $\endgroup$ Commented Oct 28, 2015 at 7:44
  • $\begingroup$ Thanks for the info, Patrick. I wrote the code first using the built in constants, then took them out to see if they were the culprit. I submitted my question with "typed-in" constants, just for simplicity, but thanks anyhow. I have looked at the question you referenced for me. A lot to study there. Many thanks. Bill $\endgroup$
    – BillT
    Commented Oct 28, 2015 at 7:58
  • $\begingroup$ J.M.: PlanckRadiationLaw[ ]: Way cool, didn't know about it. Thanks. $\endgroup$
    – BillT
    Commented Oct 28, 2015 at 8:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.