# Gravitational equations used in model of orbiting bodies

Tags:
1. Feb 17, 2015

### nearc

In practice I’ve found that a valid gravitational model of orbiting bodies only works when the force is computed with only the other mass and not both masses. Thus, the original equation does not work but the modified one does. Is using one mass ok or am I doing something wrong? thanks. [also i included is the agent based model i'm using [you will need to change the file extension to .nlogo], it can be run with a free download of netlogo [ https://ccl.northwestern.edu/netlogo/download.shtml ]]

F = G*m1*m2/ r^2, original

F = G*m1/ r^2, modified

using Finite difference; Euler's method. with the time step is built into the gravitational constant, G

valuenew=valueold + time step*differential equation

mi, mj, mass of objects,

$$d_x=m_{i_x}-m_{j_x}$$

$$d_y=m_{i_y}-m_{j_y}$$

$$R^2=d^2_x+d^2_y$$

$$F = \frac {Gm_im_j}{R^2}$$

$$\Theta = tan^{-1}(\frac {d_y}{d_x})$$

$$F_{x_{new}}= F_{x_{old}}+ Fcos(\Theta)$$

$$F_{y_{new}}= F_{y_{old}}+ Fsin(\Theta)$$

$$v_{x_{new}}= v_{x_{old}}+ F_{x_{new}}$$

$$v_{y_{new}}= v_{y_{old}}+ F_{y_{new}}$$

$$m_{ix_{new}}= m_{ix_{old}}+ v_{x_{new}}$$

$$m_{iy_{new}}= m_{iy_{old}}+ v_{y_{new}}$$

Rewritten in algorithm form [i.e. computational model]:

$$F_{ix_{new}} =F_{ix_{old}} + G\sum_{j=1}^{k} \frac{m_im_j}{{(m_{i_x }-m_{j_x }})^2 +({m_{i_y }-m_{j_y }})^2} cos(tan^{-1}(\frac { m_{i_x }-m_{j_x } } { m_{i_y }-m_{j_y } }))), i\neq j$$

$$F_{iy_{new}} =F_{iy_{old}} + G\sum_{j=1}^{k} \frac{m_im_j}{{(m_{i_x }-m_{j_x }})^2 +({m_{i_y }-m_{j_y }})^2} sin(tan^{-1}(\frac { m_{i_x }-m_{j_x } } { m_{i_y }-m_{j_y } }))), i\neq j$$

$$v_{x_{new}}= v_{x_{old}}+ F_{x_{new}}$$

$$v_{y_{new}}= v_{y_{old}}+ F_{y_{new}}$$

$$m_{ix_{new}}= m_{ix_{old}}+ v_{x_{new}}$$

$$m_{iy_{new}}= m_{iy_{old}}+ v_{y_{new}}$$

#### Attached Files:

• ###### earth03.txt
File size:
12.1 KB
Views:
92
Last edited: Feb 17, 2015
2. Feb 17, 2015

### Staff: Mentor

The original formula always works (as long as you can neglect relativistic effects), the second one will never work because the units do not match.
In many cases, it is sufficient to neglect the influence of the object you care about on the other mass, then $a=\frac{F}{m}=\frac{GM}{r^2}$ will do the job, but that is different from your second equation.

Most of the equations in your post are wrong.

3. Feb 17, 2015

### nearc

i see the two initital distance equations where wrong and i fixed them, can you point out the other ones that are wrong? also i still don't know why a simulation with F=GM1M2/R^2 does not work but one with F=GM1/R^2 does?

4. Feb 17, 2015

### TurtleMeister

F=GM1/R^2 does not work. Maybe you mean A2=GM1/R^2 ?

You must include both masses to get the force. Per Newton's third law, the force on one body will always be equal in magnitude, but opposite in polarity, to the force on the other body. However, the magnitudes of acceleration will be different if their masses are different:

$$F_1=G\frac{M_1M_2}{R^2}$$
$$F_2=-G\frac{M_1M_2}{R^2}$$
$$A_1=G\frac{M_2}{R^2}$$
$$A_2=-G\frac{M_1}{R^2}$$

5. Feb 18, 2015

### Staff: Mentor

All with inconsistent units, so nearly all of them. And those where you take the previous force and increase it step by step based on the total force.
See TurtleMeister, but I'm surprised your formulas lead to anything reasonable at all. Maybe some lucky coincidence for specific time steps.

6. Feb 18, 2015

### nearc

the only equations i can find with inconsistent are:

$$v_{x_{new}}= v_{x_{old}}+ F_{x_{new}}$$

$$v_{y_{new}}= v_{y_{old}}+ F_{y_{new}}$$

can you point out how the other ones are also inconsistent?

are you saying these equations are wrong?:

$$F_{x_{new}}= F_{x_{old}}+ Fcos(\Theta)$$

$$F_{y_{new}}= F_{y_{old}}+ Fsin(\Theta)$$

i have used various time steps, grid spacing, number of bodies. all of the simulations work fine with one mass but not both masses.

can anyone point to an example of a n-body gravitational model?

7. Feb 18, 2015

### Staff: Mentor

- adding velocities to masses (changing masses are weird on their own)
- adding forces to the gravitational constant (the mass units in the sums cancel)

I don't see any way how they can make sense.

One mass is just floating in space?

Do you get a stable ellipsis in any setup?

http://www.codeproject.com/Articles/22438/Gravity-and-Collision-Simulation-in-C
http://users.softlab.ece.ntua.gr/~ttsiod/gravity.html

Random google hits, I don't know them.

8. Feb 24, 2015

### nearc

velocities are not being added to masses, if you are referring to:

$$m_{ix_{new}}= m_{ix_{old}}+ v_{x_{new}}$$

that is the x position of mass i, being adjusted by the the velocity which is multiplied by the time step [remember the time step is built into G]. velocity multiplied by time yields distance, so that equation is x_new = x_old + delta distance

i'm seeing where i add forces to the gravitational constant which equations are you referring to?

9. Mar 2, 2015

### dean barry

The only equation that comes to mind is :
total acceleration (of both bodies) = ( G * ( M + m ) ) / r ^2

If m is negligible, then you get : acceleration of m = ( G * M ) / r ^2
(M is deemed to be non accelerating)