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]
Quantity[1, "PlanckConstant"],Quantity[1, "SpeedOfLight"]andQuantity[1, "BoltzmannConstant"]. See https://mathematica.stackexchange.com/questions/16446/are-mathematica-9-and-10-units-really-slow – Patrick Stevens Oct 28 '15 at 07:38QuantityMagnitude[]is particularly useful.) There is also the newPlanckRadiationLaw[]function. – J. M.'s missing motivation Oct 28 '15 at 07:44