<p>As <a href="https://astronomy.stackexchange.com/users/21/barrycarter">barrycarter</a> mentioned in his comment, you should be more concerned with units and less with scale.</p>

<p>Generally, it's best to stick to conventional units that people recognize. (It will keep your head on straight and make it easier for others to review your work.) In astronomy, these are a little different than the standard SI units, since things are—shall we say—<em>big</em>, and numbers get out of hand quickly (as you have noted). Here are some units suggested in the <a href="https://en.wikipedia.org/wiki/Astronomical_system_of_units" rel="nofollow noreferrer">Astronomical system of units Wikipedia page</a>:</p>

<ul>
<li><em>Time</em>: Day. This is probably not too important, so feel free to use seconds here. (After all, it's only a 5 order of magnitude difference.)</li>
<li><em>Mass</em>: There are several conventions, but the one I've personally seen most is solar masses. Since you're modeling our solar system, it makes a convenient reference.</li>
<li><em>Length</em>: I would definitely use astronomical units. (What an appropriate name!)</li>
</ul>

<p>If you stick to these units, you should be able to limit error due to rounding and reduce the computational load of large numbers.</p>

CC BY-SA 3.0
2015-09-23T19:14:41.823Z
Thanks for the answer. Yes, using au makes much more sense. But there is still something that bugs me.
In the wiki page you linked, 1 solar mass is 1.988*E30 and GM☉ is 1.327 × E20 kg m3s−2
So it's in meters and kilogram format.
As I'm using equation F=GMm/r^2;
Shouldn't I convert G format to au and solar mass If I am using au in r (distance) and solar mass in body masses?
I mean It's basicly same problem with the scale problem I mentioned in the main question. There is something that I can't convice myself about it, and don't know why.
OldBerkay
CC BY-SA 3.0
2015-09-23T19:19:06.283Z
To make it more clear:
If you checked my excell sheet, as I am scaling down the lengths, I am also scaling down the masses, so the body densities remain same.
Is this really necessary? Length and mass are two independent units, It shouldn't effect the one another when I scale the one down. But on the otherhand, density should remain same. So they are dependent to each other by density afterall?
OldBerkay
CC BY-SA 3.0
2015-09-24T13:57:49.560Z
You don't need to be concerned with density at all. Just convert your units until they have manageable scales.
dpdwilson
CC BY-SA 3.0
2015-09-22T13:26:33.583Z
2015-09-22T13:26:33.583Z
2017-04-13T12:59:06.910Z
dpdwilson
<p>Consider a nearly circular orbit. On average, $ v = 2 \pi r / T $, and the gravitational force balances the centrifugal force:
$$ {G M m \over r^2} = {m v^2 \over r} = {4 \pi^2 m r \over T^2} $$
Solve for $G$ and substitute values for Earth's orbit around the Sun:
$$ G = {4 \pi^2 r^3 \over M T^2 } = 4 \pi^2 {\mathrm{AU}^3 \over M_{\odot} \ \mathrm{y}^2} $$
If you want day units instead, use a conversion factor to cancel the years: 
$$ G = 39.5 {\mathrm{AU}^3 \over M_{\odot} \ \mathrm{y}^2}
\left( {1 \ \mathrm{y} \over 365.25 \ \mathrm{d}} \right)^2
= 2.96 \times 10^{-4} {\mathrm{AU}^3 \over M_{\odot} \ \mathrm{d}^2} $$
The factor-label method also works if you start with the MKS value:
$$ G = 6.67 \times 10^{-11} \mathrm{m^3 \over kg \ s^2}
\left( {1 \ \mathrm{AU} \over 1.496 \times 10^{11} \ \mathrm{m}} \right)^3
\left( {1.99 \times 10^{30} \ \mathrm{kg} \over 1 \ M_{\odot}} \right)
\left( {86400 \ \mathrm{s} \over 1 \ \mathrm{d}} \right)^2
= {2.96 \times 10^{-4} {\mathrm{AU}^3 \over M_{\odot} \ \mathrm{d}^2}} $$
Validation tests will tell whether your simulation works correctly. Set up a variety of simple systems where you have a clear idea of what should happen, and then check what actually does happen.</p>

CC BY-SA 3.0
2016-04-11T02:51:02.217Z
2016-04-11T02:51:02.217Z
Mike G
<p>I programmed one by myself some time ago. I used full SI units in combination with doubles (64-bit floating numbers). They work great for the scale of our solar system and are still extremly precise.</p>

<pre><code>        var sun = new Star();
        sun.Position = new Vector3D(0,0,0);
        sun.Velocity = new Vector3D(0,0,0);
        sun.Mass = 1.998855e30;

        var earth = new Planet();
        earth.Mass = 5.9722e24;
        earth.Position = new Vector3D(0, 149.6e9, 0);
        earth.Velocity = new Vector3D(29780,0,0);

        system.World.Objects.Add(sun);
        system.World.Objects.Add(earth);
</code></pre>

<p>If you are intersted, my code for this simulation is on github: <a href="https://github.com/RononDex/Simulation" rel="nofollow">https://github.com/RononDex/Simulation</a></p>

<p>The simulation itself is in the subfolder <code>Simulation.Testing</code></p>

CC BY-SA 3.0
2016-04-11T11:34:20.573Z
"sun.Mass = 1.998855e30;" That is still not scaled down...
SE - stop firing the good guys
CC BY-SA 3.0
2016-04-11T11:41:36.453Z
@Hohmannfan As I said, I used SI values, thats not scaled down.
RononDex
CC BY-SA 3.0
2016-04-11T11:44:36.113Z
What I mean is that in many of the required calculations, you have to multiply several numbers of that kind of magnitude, before getting back to reasonable numbers. Even though the constant itself is well within limits, they may still cause unexpected errors in the calculations.
SE - stop firing the good guys
CC BY-SA 3.0
2016-04-11T11:49:10.543Z
@Hohmannfan I suggest you read some resources on the topic of double precision (64-bit floats), Even for values like the mass of the sun with 10^30 the precision is still better than 0.0001kg (if 1 = 1kg)
RononDex
CC BY-SA 3.0
2016-04-11T11:52:21.433Z
OK, the exponent is allocated 11 bits, and that is still a magnitude of 4 bits larger than the worst calculation example I can think of. Point taken.
SE - stop firing the good guys
CC BY-SA 3.0
2016-04-11T11:20:01.050Z
2016-04-11T11:20:01.050Z
RononDex
<p>Okay, I am seriously ashamed for asking this especialy when I geniualy study on physics but there is something that bugs me with the simulation I am working on.</p>
<p>I am re-creating the solar system in an n-body simulation that i programmed before. And I've a problem with scaling down the solar data. So even if I use kg and km for the metric units, the values are far bigger than the variables can hold in programming. Also as some of you know, bigger the value is, bigger the floating point error it makes. (error noise in data) Also it makes it slower to process.</p>
<p>I decided to scale down the data with a reference point, and for that, I took the earth's radius as 1 unit. And scaled down every other distance and radius according to it. (So a unit is 6371 km just to be clear)</p>
<p>But I am not sure whether if I should scale down the mass or not. My common sense says that I should scale down the mass so density of each body should remain same. So I took the density, and calculated a new mass value for each body, with the new scaled down radius.
But I am somehow couldn't conviced myself about If it's true or not. So here I am, asking to you :) Should I also scale down the mass?</p>
<p>PS.1: I used using <span class="math-container">$F = GMm/r^2$</span> equation for the calculactions as usual. (Iterating it through each body pairs)</p>
<p>If there are other programmers like me interested in making a simulation like this, how did you accomplish this data size problem? Are there any better solutions than scaling down the values?</p>
<p>PS. I have created an excel file that does the scale conversion. So I am sharing  the sheet in OneDrive. (<a href="http://1drv.ms/1NIekGo" rel="nofollow noreferrer">http://1drv.ms/1NIekGo</a>) If you can check my calculations and values, that I'd also be really helpful to me. Thanks for any help.</p>

CC BY-SA 3.0
2015-09-23T19:24:04.637Z
@barrycarter
So which G constant format should I use in the F = GMM/r^2 equation? I mean if I use mass in relative proportions and lengths in AU, usual G consant units become obsolete. I need to convert it, but how do I do it with relative mass values?
OldBerkay
CC BY-SA 3.0
2016-04-14T17:20:15.527Z
Are you clear on how unit conversion works? For example, if you're given the value of the gravitational constant in units of meters^3 / (kilograms * seconds^2), would you know how to convert that to the value of the gravitation constant in units of AU^3 / (Earth masses * years^2)?
Hypnosifl
<solar-system><n-body-simulations><units>
How to scale down solar system data to simulatable values
OldBerkay
# How to scale down solar system data to simulatable values

(Asked by: username_0 on 2015-09-22)

Okay, I am seriously ashamed for asking this especialy when I geniualy study on physics but there is something that bugs me with the simulation I am working on.

I am re-creating the solar system in an n-body simulation that i programmed before. And I've a problem with scaling down the solar data. So even if I use kg and km for the metric units, the values are far bigger than the variables can hold in programming. Also as some of you know, bigger the value is, bigger the floating point error it makes. (error noise in data) Also it makes it slower to process.

I decided to scale down the data with a reference point, and for that, I took the earth's radius as 1 unit. And scaled down every other distance and radius according to it. (So a unit is 6371 km just to be clear)

But I am not sure whether if I should scale down the mass or not. My common sense says that I should scale down the mass so density of each body should remain same. So I took the density, and calculated a new mass value for each body, with the new scaled down radius.
But I am somehow couldn't conviced myself about If it's true or not. So here I am, asking to you :) Should I also scale down the mass?

PS.1: I used using $F = GMm/r^2$ equation for the calculactions as usual. (Iterating it through each body pairs)

If there are other programmers like me interested in making a simulation like this, how did you accomplish this data size problem? Are there any better solutions than scaling down the values?

PS. I have created an excel file that does the scale conversion. So I am sharing the sheet in OneDrive. (<http://1drv.ms/1NIekGo>) If you can check my calculations and values, that I'd also be really helpful to me. Thanks for any help.

**Tags:** solar-system, n-body-simulations, units

> **Comments:**
> **username_0**: @barrycarter So which G constant format should I use in the F = GMM/r^2 equation? I mean if I use mass in relative proportions and lengths in AU, usual G consant units become obsolete. I need to convert it, but how do I do it with relative mass values?  
> **username_1**: Are you clear on how unit conversion works? For example, if you're given the value of the gravitational constant in units of meters^3 / (kilograms * seconds^2), would you know how to convert that to the value of the gravitation constant in units of AU^3 / (Earth masses * years^2)?  

---

## 3 answers

### Answer by username_2 on 2015-09-22. Score: 5

As [barrycarter](https://astronomy.stackexchange.com/users/21/barrycarter) mentioned in his comment, you should be more concerned with units and less with scale.

Generally, it's best to stick to conventional units that people recognize. (It will keep your head on straight and make it easier for others to review your work.) In astronomy, these are a little different than the standard SI units, since things are—shall we say—*big*, and numbers get out of hand quickly (as you have noted). Here are some units suggested in the [Astronomical system of units Wikipedia page](https://en.wikipedia.org/wiki/Astronomical_system_of_units):

* *Time*: Day. This is probably not too important, so feel free to use seconds here. (After all, it's only a 5 order of magnitude difference.)
* *Mass*: There are several conventions, but the one I've personally seen most is solar masses. Since you're modeling our solar system, it makes a convenient reference.
* *Length*: I would definitely use astronomical units. (What an appropriate name!)

If you stick to these units, you should be able to limit error due to rounding and reduce the computational load of large numbers.

> **Comments:**
> **username_0**: Thanks for the answer. Yes, using au makes much more sense. But there is still something that bugs me. In the wiki page you linked, 1 solar mass is 1.988*E30 and GM☉ is 1.327 × E20 kg m3s−2 So it's in meters and kilogram format. As I'm using equation F=GMm/r^2; Shouldn't I convert G format to au and solar mass If I am using au in r (distance) and solar mass in body masses? I mean It's basicly same problem with the scale problem I mentioned in the main question. There is something that I can't convice myself about it, and don't know why.  
> **username_0**: To make it more clear: If you checked my excell sheet, as I am scaling down the lengths, I am also scaling down the masses, so the body densities remain same. Is this really necessary? Length and mass are two independent units, It shouldn't effect the one another when I scale the one down. But on the otherhand, density should remain same. So they are dependent to each other by density afterall?  
> **username_2**: You don't need to be concerned with density at all. Just convert your units until they have manageable scales.  

---

### Answer by username_3 on 2016-04-11. Score: 4

Consider a nearly circular orbit. On average, $ v = 2 \pi r / T $, and the gravitational force balances the centrifugal force:
$$ {G M m \over r^2} = {m v^2 \over r} = {4 \pi^2 m r \over T^2} $$
Solve for $G$ and substitute values for Earth's orbit around the Sun:
$$ G = {4 \pi^2 r^3 \over M T^2 } = 4 \pi^2 {\mathrm{AU}^3 \over M\_{\odot} \ \mathrm{y}^2} $$
If you want day units instead, use a conversion factor to cancel the years:
$$ G = 39.5 {\mathrm{AU}^3 \over M\_{\odot} \ \mathrm{y}^2}
\left( {1 \ \mathrm{y} \over 365.25 \ \mathrm{d}} \right)^2
= 2.96 \times 10^{-4} {\mathrm{AU}^3 \over M\_{\odot} \ \mathrm{d}^2} $$
The factor-label method also works if you start with the MKS value:
$$ G = 6.67 \times 10^{-11} \mathrm{m^3 \over kg \ s^2}
\left( {1 \ \mathrm{AU} \over 1.496 \times 10^{11} \ \mathrm{m}} \right)^3
\left( {1.99 \times 10^{30} \ \mathrm{kg} \over 1 \ M\_{\odot}} \right)
\left( {86400 \ \mathrm{s} \over 1 \ \mathrm{d}} \right)^2
= {2.96 \times 10^{-4} {\mathrm{AU}^3 \over M\_{\odot} \ \mathrm{d}^2}} $$
Validation tests will tell whether your simulation works correctly. Set up a variety of simple systems where you have a clear idea of what should happen, and then check what actually does happen.


---

### Answer by username_4 on 2016-04-11. Score: 1

I programmed one by myself some time ago. I used full SI units in combination with doubles (64-bit floating numbers). They work great for the scale of our solar system and are still extremly precise.

```
        var sun = new Star();
        sun.Position = new Vector3D(0,0,0);
        sun.Velocity = new Vector3D(0,0,0);
        sun.Mass = 1.998855e30;

        var earth = new Planet();
        earth.Mass = 5.9722e24;
        earth.Position = new Vector3D(0, 149.6e9, 0);
        earth.Velocity = new Vector3D(29780,0,0);

        system.World.Objects.Add(sun);
        system.World.Objects.Add(earth);

```

If you are intersted, my code for this simulation is on github: <https://github.com/username_4/Simulation>

The simulation itself is in the subfolder `Simulation.Testing`

> **Comments:**
> **username_5**: "sun.Mass = 1.998855e30;" That is still not scaled down...  
> **username_4**: @Hohmannfan As I said, I used SI values, thats not scaled down.  
> **username_5**: What I mean is that in many of the required calculations, you have to multiply several numbers of that kind of magnitude, before getting back to reasonable numbers. Even though the constant itself is well within limits, they may still cause unexpected errors in the calculations.  
> **username_4**: @Hohmannfan I suggest you read some resources on the topic of double precision (64-bit floats), Even for values like the mass of the sun with 10^30 the precision is still better than 0.0001kg (if 1 = 1kg)  
> **username_5**: OK, the exponent is allocated 11 bits, and that is still a magnitude of 4 bits larger than the worst calculation example I can think of. Point taken.  

---

