2

I'm using MMA 12.2. Trying to put together some astronomy pages, but the output of the command below is in miles. I would rather have it in SI units instead.

On my system evaluating $UnitSystem returns Imperial.

Can I (or even should I) change the units for the whole Notebook, or even all of MMA?

output of command above

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
fiz
  • 736
  • 1
  • 6
  • 13

2 Answers2

4

Yes, you can change it:

$UnitSystem = "Metric"

If you want to make the change permanent, you can change the init.m file or just evaluate the command above whenever you run Mathematica.

Also, you can use the UnitConvert function:

PlanetData[PlanetData[], "Radius", "EntityAssociation"] //
Map[UnitConvert[#, Quantity[1, "AstronomicalUnit"]] &]

<|Mercury -> 0.00001631 au, Venus -> 0.00004045 au, Earth -> 0.000042587563 au, Mars -> 0.000022658 au, Jupiter -> 0.0004675 au, Saturn -> 0.00038971 au, Uranus -> 0.0001695 au, Neptune -> 0.0001646 au|>

Searke
  • 4,404
  • 20
  • 23
4

If you don't want to change $UnitSystem globally

Block[{$UnitSystem = "Metric"}, PlanetData[PlanetData[], "Radius", "EntityAssociation"]]
Rohit Namjoshi
  • 10,212
  • 6
  • 16
  • 67
  • Does that work to return km units? I still get miles. – MarcoB Jan 04 '21 at 18:43
  • @MarcoB Strange, I get km even though $UnitSystem is Imperial outside the Block. – Rohit Namjoshi Jan 04 '21 at 18:45
  • MarcoB --- It changes to "km" for me. – fiz Jan 04 '21 at 19:01
  • Rohit.....That's beautiful!....it's great, it's easy, and it works, and I'm gonna use it. I'll also have to try and understand WHY it works. I've been messing around with this for 2 weeks, and I greatly appreciate this! Thank you! – fiz Jan 04 '21 at 19:03
  • @RohitNamjoshi --- for a quantity (same project same type command you helped with before, MMA gives Density data for these planets in "g/cm^3"....is there a way to force this to be "kg/m^3"? ugh....MMA does NOT manage units very gracefully. – fiz Jan 05 '21 at 17:25
  • @fiz That will have to be done explicitly since for Metric/SI the units are g/cm^3. One way PlanetData[PlanetData[], "Density", "EntityAssociation"] // Map[UnitConvert[#, "Kilograms"/"Meters"^3] &] – Rohit Namjoshi Jan 06 '21 at 01:07
  • @fiz I see that you asked this in a new question. The responses there are better than what I suggested above. – Rohit Namjoshi Jan 06 '21 at 01:18