# N-body correct scaling

I realized an usual way to scale an N-body problem for an N-body simulation is by choosing units such that gravitational constant $$G = 1$$, but I'm probably doing it the wrong way. Suppose I simply have a planet moving around the Sun (which I consider as the center of my reference frame). For example I choose

$$\begin{equation} M_s = M_{sun} + M_1 \tag{1} \end{equation}$$

$$\begin{equation} D_s = D_1 \tag{2} \end{equation}$$ as my mass and distance scaling units. Than I should choose $$T_s$$ in such a way that my new $$G$$, which I call $$G'$$, is equal $$1$$. So $$\begin{equation} G' = 1 = \frac{1}{G} \frac{D_s^{3}}{M_sT_s^2} \tag{3} \end{equation}$$ brings me to $$\begin{equation} T_s = \sqrt{\frac{D_s^3}{GM_s}} \tag{4} \end{equation}$$

After that, I divide masses and distances by $$M_s$$ and $$D_s$$, and velocities by $$D_s/T_s$$. This is what I understood from what I found about this scaling. Am i doing something wrong? I even tried different way to set $$D_s$$ and $$M_s$$, different starting units, but I always get wrong outputs.

Edit 1

This is the function I'm using (C++), with x as the vector containing velocity and position of the body moving aroun the Sun and y position vector of the Sun (considering the above example).

d = sqrt(pow((x - y),2) + pow((x - y),2) + pow((x - y),2));

//x system
p = x;
p = -G*m*(x - y)/pow(d,3);
//y system
p = x;
p = -G*m*(x - y)/pow(d,3);
//z system
p = x;
p = -G*m*(x - y)/pow(d,3);


The equations are specific for the choosen planet, so there's only the Sun mass on the right hand side. The $$G$$ is equal $$1$$ in this case. The original dimensions are astronomic units for distances, kilograms for masses and days for times, so $$[G] = \frac{AU^3}{kg\,days^2}$$.

• This looks all correct, up to the point where the formula is for $\frac1{G'}$ which does nothing here as $G'=1$. For more one would have to see some of the code, with the original quantities and the de-scaling process. – Lutz Lehmann Jan 10 at 16:11
• I meant the translation of the initial data, what are the original initial position and velocity, what are the translated values? And what is the meaning of "I always get wrong outputs", what do you compare against and how far away is it? In the edit I only find the use of two index schemes slightly confusing, why not use x[0..2] also for the positions as in y[0..2], and then x[3..5] for the velocities? Apart from that it looks standard and correct. – Lutz Lehmann Jan 10 at 17:41
• @LutzLehmann Sorry, I forgot to modify some index properly while posting the function. What I used to get was empty 3d plots or straight lines, but I just realized the problem was actually inside the de-scaling function, which was embedded in a write-on-file function. Thank you :-) – Martrin Jan 10 at 18:15