Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to use Mathematica units more often, but I've run into the following problem:

    (*Define some unitful constants*)
    q = UnitConvert[Quantity["elementary charge"]];
    k = UnitConvert[Quantity["Boltzmann Constant"]];
    T = Quantity[300, "Kelvin"];
    V = Quantity[5, "Volt"];
    (*Do a simple calculation*)
    UnitConvert[(q V)/(k T)]

The above code outputs

    Quantity[193.409, ("Kelvins")/("KelvinsDifference")]

which really should just be 193.409, since the units cancel, but Mathematica insists on a distinction between absolute temperature and temperature differences. I understand that such a distinction is useful in conversions, but the above is quite a nuisance.

Is there a way to prevent this? I'd rather not have to put in QuantityMagnitude calls every time I need to cancel some Kelvins.

Thanks!

share|improve this question
    
I think this behaviour has changed: Kelvin used to be interpreted by Wolfram Alpha as KelvinDifference, whereas Kelvins was recognized by Mathematica as a built-in unit and directly interpreted as Kelvin. Since a few months, Kelvin is interpreted as Kelvins, so the error appears to have gone away. (Of course, the unit of the Boltzmann constant is stilll incorrect, see Xerxes' answer.) –  Martin J.H. Nov 10 at 11:30

1 Answer 1

up vote 13 down vote accepted

This appears to be a bug. The dimensions of the Boltzmann constant are incorrect. In fact, all the physical constants I checked have TemperatureUnit where they should have TemperatureDifferenceUnit. You should only have to make a substitution when making calls to physical constants in Quantity:

q = UnitConvert[Quantity["elementary charge"]];
k = (UnitConvert[Quantity["Boltzmann Constant"]] /. 
   "Kelvins" -> "KelvinsDifference");
T = Quantity[300, "Kelvin"];
V = Quantity[5, "Volt"];
UnitConvert[(q V)/(k T)]
(* 193.409 *)

EDIT: Alternatively, since Quantity seems to be calling away to Alpha, you could do

k = UnitConvert[Quantity["Boltzmann Constant (energy per temperature difference)"]]
share|improve this answer
    
Thanks! I agree: it makes a lot more sense for those to be TemperatureDifferenceUnit. And your fix solves my problem! –  Sam Bader Mar 7 '13 at 1:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.