2
$\begingroup$

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

$\endgroup$
1

2 Answers 2

4
$\begingroup$

If you don't want to change $UnitSystem globally

Block[{$UnitSystem = "Metric"}, PlanetData[PlanetData[], "Radius", "EntityAssociation"]]
$\endgroup$
7
  • $\begingroup$ Does that work to return km units? I still get miles. $\endgroup$
    – MarcoB
    Jan 4, 2021 at 18:43
  • $\begingroup$ @MarcoB Strange, I get km even though $UnitSystem is Imperial outside the Block. $\endgroup$ Jan 4, 2021 at 18:45
  • $\begingroup$ MarcoB --- It changes to "km" for me. $\endgroup$
    – fiz
    Jan 4, 2021 at 19:01
  • $\begingroup$ 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! $\endgroup$
    – fiz
    Jan 4, 2021 at 19:03
  • $\begingroup$ @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. $\endgroup$
    – fiz
    Jan 5, 2021 at 17:25
4
$\begingroup$

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|>
$\endgroup$
2
  • $\begingroup$ Does the global change work to return km units? I still get miles. $\endgroup$
    – MarcoB
    Jan 4, 2021 at 18:43
  • 1
    $\begingroup$ Also UnitConvert[PlanetData[PlanetData[], "Radius", "EntityAssociation"], "AstronomicalUnit"] works just as well. $\endgroup$
    – MarcoB
    Jan 4, 2021 at 18:44

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