Simple particles simulation (gravity)

In summary, the conversation discusses the issues with a 2 particle simple orbit simulation, specifically regarding the equations and code used. The use of a time step of 1 second is mentioned as a potential issue, as well as the use of Euler method instead of 4th order Runge-Kutta for integration. It is suggested that these factors could be causing issues with accuracy and stability in the simulation.
  • #1
qwe
25
0
i believe I'm using the correct equations, but the orbit won't work. here is the relevant code for a 2 particle simple orbit simulation. I'm not sure what I'm doing wrong

Code:
...

timeStep = 1.0
gravityConstant = 6.67384 * 10.0 ^ -11.0

...

// (initialize particles)
// p[n].m: mass, p[n].x: initial x position, p[n].vz: initial velocity vector along z axis

            p[0].m = 1.0
            p[1].m = 1.0

            p[0].t = 0
            p[0].x = 10.0

            p[1].t = 0
            p[1].x = -10.0

// initial velocity = sqrt(m2 ^2 * G / m1 + m2 * distance)

            p[0].vz = sqrt( ( p[1].m * p[1].m * gravityConstant ) / ( p[0].m + p[1].m * 10.0 ) )
            p[1].vz = sqrt( ( p[0].m * p[0].m * gravityConstant ) / ( p[1].m + p[0].m * 10.0 ) ) * -1

...

// (each loop, for each particle... p[n] is current particle, p[m] is other particle)

                        // calculate distance
                        dx# = p[m].x - p[n].x
                        dy# = p[m].y - p[n].y
                        dz# = p[m].z - p[n].z
                        distance# = sqrt( dx# * dx# + dy# * dy# + dz# * dz# )
                        // calculate force
                        force# = (gravityConstant * p[n].m * p[m].m) / (distance# * distance#)
                        // calculate acceleration, include timestep
                        acceleration# = (force# / p[n].m) * timeStep
                        // calculate unit vector and calculate magnitude of vector (acceleration)
                        p[n].vx = p[n].vx + dx# * (acceleration# / distance# )
                        p[n].vy = p[n].vy + dy# * (acceleration# / distance# )
                        p[n].vz = p[n].vz + dz# * (acceleration# / distance# )
 
Last edited:
Physics news on Phys.org
  • #2
Without going through the code in details:
1. I don't see where you update particle position. I assume you just omitted it for brevity.
2. Gravitation force between 2 1kg masses at 10 meters is not exactly very strong.
3. With a time step of 1s your are going to have a lot of very small steps, running into precision and error accumulation issues
4. Euler method sux. Bite the bullet and code up 4th order Runge-Kutta, then you can increase your step size to a sensible value.
 
  • #3
am i doing the timestep correctly? the bigger the timestep, the more acceleration applied. that doesn't seem right, the orbit shape changes based on the timestep, but it shouldn't
 
  • #4
Numerical integration suffers problems with accuracy and stability. The simple method you are using is called Euler method and isn't good. As Delta said, you should try 4th order Runge-Kutta.
 

1. What is "Simple particles simulation (gravity)"?

"Simple particles simulation (gravity)" is a computer program or model that simulates the movement of particles under the influence of gravity. It is often used in scientific research to study the behavior of objects in space or on a smaller scale, such as atoms in a molecule.

2. How does the simulation work?

The simulation works by using mathematical equations to calculate the forces of attraction between particles based on their masses and distances from each other. These forces are then used to determine the particles' movements over time.

3. What factors are important in a simple particles simulation?

The most important factors in a simple particles simulation are the mass and initial positions of the particles, as well as the strength of the gravitational force between them. The simulation may also take into account other forces, such as friction or air resistance, depending on the specific scenario being simulated.

4. What are some real-world applications of simple particles simulations?

Simple particles simulations can be applied to a wide range of fields, including astrophysics, material science, and chemistry. They are used to study the formation of planets and galaxies, the behavior of materials under different conditions, and the interactions between atoms and molecules in chemical reactions.

5. How accurate are simple particles simulations?

The accuracy of a simple particles simulation depends on the complexity of the model and the accuracy of the initial input parameters. In general, the simulation will become more accurate as the number of particles and the time increments used in the simulation increase. However, there may still be some discrepancies between the simulation and real-world observations due to the simplifications and assumptions made in the model.

Similar threads

  • High Energy, Nuclear, Particle Physics
Replies
1
Views
912
  • High Energy, Nuclear, Particle Physics
Replies
6
Views
1K
  • High Energy, Nuclear, Particle Physics
Replies
14
Views
2K
  • Calculus and Beyond Homework Help
Replies
8
Views
1K
  • High Energy, Nuclear, Particle Physics
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Replies
2
Views
460
Replies
12
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
812
  • Programming and Computer Science
Replies
4
Views
1K
Back
Top