Created
July 9, 2021 17:09
-
-
Save CodeDrome/38344fc29eebcf229baaea9601b2d28e to your computer and use it in GitHub Desktop.
mathjsunits06.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function astronomical() | |
{ | |
// create length units for astronomy | |
math.createUnit('lightyear', '9460730777119.56 km'); | |
math.createUnit('parsec', '30856775714409.19 km'); | |
math.createUnit('AU', '149597870.7 km'); | |
// Proxima Centauri is the nearest star to the Sun | |
const EarthToProximaCentauri = math.unit(4.2465, 'lightyear'); | |
output(`EarthToProximaCentauri: ${EarthToProximaCentauri}`); | |
output(`EarthToProximaCentauri.to('km'): ${EarthToProximaCentauri.to('km')}`); | |
output(`EarthToProximaCentauri.to('parsec'): ${EarthToProximaCentauri.to('parsec')}`); | |
output("<br>"); | |
const EarthToSun = math.unit(1.0, 'AU'); | |
output(`EarthToSun: ${EarthToSun}`); | |
output(`EarthToSun.to('miles'): ${EarthToSun.to('miles')}`); | |
output(`EarthToSun.to('miles').toNumber(): ${EarthToSun.to('miles').toNumber()}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment