-2
$\begingroup$

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?

$\endgroup$
  • 2
    $\begingroup$ What you are getting is correct. The operations you are doing are not orderless -- order matters. $\endgroup$ – m_goldberg Feb 20 '14 at 1:50
  • $\begingroup$ How does UnitConvert know I didn't want the increment and return 20K? $\endgroup$ – george2079 Feb 20 '14 at 2:59
  • $\begingroup$ @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. $\endgroup$ – bobthechemist Feb 20 '14 at 3:41
  • 2
    $\begingroup$ From my point of view, there is no meaning in "double the temperature". $\endgroup$ – MMM Feb 20 '14 at 7:33
  • 1
    $\begingroup$ reference.wolfram.com/mathematica/tutorial/… $\endgroup$ – george2079 Feb 20 '14 at 21:29
2
$\begingroup$

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.
$\endgroup$
  • 1
    $\begingroup$ Related topic on Physics.SE $\endgroup$ – Kuba Feb 20 '14 at 12:50
  • $\begingroup$ I hope the new FormulaData takes this into account $\endgroup$ – Rojo Mar 2 '14 at 23:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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