Message Boards Message Boards

1
|
1548 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Why did the Units switch from celsius to kelvin when I changed my code here?

Posted 1 year ago
2 Replies

tutorial/TemperatureUnits

There has been a recent change in the behaviour of temperature quantities in Mathematica. It was decided that it does not make much sense to add two celsius temperatures, or to multiply one by a coefficient. The moving average implies just those two steps:

MovingAverage[{Quantity[a, "DegreesCelsius"],
  Quantity[b, "DegreesCelsius"]}, 2]

and the result is expressed in Kelvins, for which the separate steps make sense. Try this:

Quantity[a, "DegreesCelsius"] + Quantity[b, "DegreesCelsius"]

Strangely enough, Mean is not affected:

Mean[{Quantity[a, "DegreesCelsius"],
  Quantity[b, "DegreesCelsius"]}]

In your specific case, I would suggest to reconvert the moving averages to Celsius.

POSTED BY: Gianluca Gorni

Thank you for the suggestion!

I was able to fix it with the following code:

Grid[{UnitConvert[#1, "DegreesCelsius"], #2} & @@@ 
  Transpose[MapAt[MovingAverage[#, 2] &, HistogramList[data], 1]], 
 Dividers -> All]

or

Grid[Apply[{UnitConvert[#1, "DegreesCelsius"], #2} &, 
  Transpose[MapAt[MovingAverage[#, 2] &, HistogramList[data], 1]], 1],
  Dividers -> All]
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract