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.

When using a Quantity with the unit of "DegreesCelsius" multiplication doesn't work as expected. If you have 10 degrees and multiply it by 2 you get 20 degrees instead of the expected 293,15 degrees. This becomes a real problem if you use the temperature directly in a formula, eg. the ideal gas law. Example code:

t = Quantity[10, "DegreesCelsius"];
T = UnitConvert@t;
UnitConvert[2 * t] // N (* => 293.15 K *)
2 * T // N (* => 566.3 K *)

Is there a way to fix this behaviour to work as I expect it to?

share|improve this question
2  
What you are getting is correct. The operations you are doing are not orderless -- order matters. –  m_goldberg Feb 20 at 1:50
    
How does UnitConvert know I didn't want the increment and return 20K? –  george2079 Feb 20 at 2:59
    
@george2079 UnitConvert in this case behaves like f[x_]:=x+273.15 so the two problems look like f[2*10] = 20 + 273.15 = 293.15 and 2*f[10] = 2(10 + 273.15) = 566.3. –  bobthechemist Feb 20 at 3:41
1  
From my point of view, there is no meaning in "double the temperature". –  Jason Feb 20 at 7:33
1  

1 Answer 1

Most quantity conversions convert between quantities that have a common zero point (e.g., 0 Kg and 0 Lb are same) and these will work as the OP desires. For temperatures and other quantities where the zero points differ (e.g., 0 °K and 0 °C are not the same), one must be more careful.

I suggest the following workflow.

  1. Convert all temperature readings to one system.
  2. Do all computations in that uniform system.
  3. Back convert any results if necessary.
share|improve this answer
    
Related topic on Physics.SE –  Kuba Feb 20 at 12:50
    
I hope the new FormulaData takes this into account –  Rojo Mar 2 at 23:54

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.