Simulating N-Body Gravity Interactions: A Challenge in Computational Physics

In summary, the speaker has created a program to simulate gravity between two bodies, but is now having trouble implementing it for multiple bodies. They are attempting to find the net gravity by calculating the force between each pair of bodies, but this approach is not working. The speaker has provided their equations and an attempt at a solution, but is seeking help with their program.
  • #1
DrCheeto
2
0

Homework Statement


Hi for fun, and to understand physics better I have scripted a program that replicate gravity exerted from one force (ex the Earth rotating around the sun) and it works well. But now I want to have mutliple bodies that affect gravity and using the same equations it isn't working. To find net gravity I am just finding the force of gravity between say Earth and sun1 and sun2 then adding them up clearly this is wrong because it does not work at all.

Homework Equations


Here is my equations

Code:
        'Force
        Ftmp = (G * Ball.Mass * Planet.Mass) / (nDist * nDist)
        Force.X = Ftmp * (Ball.Pos.X - Planet.Pos.X) / nDist
        Force.Y = Ftmp * (Ball.Pos.Y - Planet.Pos.Y) / nDist
        
        'Acceleration
        Acceleration.X = Force.X / Ball.Mass
        Acceleration.Y = Force.Y / Ball.Mass
        
        'Velocity
        Ball.Velocity.X = Ball.Velocity.X + Acceleration.X
        Ball.Velocity.Y = Ball.Velocity.Y + Acceleration.Y
        
        'New Position
        Ball.Pos.X = Ball.Pos.X - Ball.Velocity.X
        Ball.Pos.Y = Ball.Pos.Y - Ball.Velocity.Y
        
        'Return new information
        Gravity = Ball

The Attempt at a Solution


My attempt was basically this
Code:
for ncount = 1 to 3
        Ftmp = (G * Ball.Mass * Planet(ncount).Mass) / (nDist * nDist)
        Force.X = force.x + Ftmp * (Ball.Pos.X - Planet(ncount).Pos.X) / nDist
        Force.Y = force.y + Ftmp * (Ball.Pos.Y - Planet(ncount).Pos.Y) / nDist
next
 
Physics news on Phys.org
  • #2
Can anyone help me?
 

1. What is an N-Body Gravity Simulation?

An N-Body Gravity Simulation is a computer program that uses numerical methods to model and simulate the gravitational interactions between multiple bodies in a system. It is commonly used in astrophysics to study the motion and behavior of celestial objects, such as planets, stars, and galaxies.

2. How does N-Body Gravity Simulation work?

N-Body Gravity Simulation works by using Newton's law of universal gravitation to calculate the gravitational forces between each pair of bodies in the system. These forces are then used to determine the accelerations of the bodies, which are used to update their positions and velocities in small time steps. This process is repeated over and over to simulate the motion of the bodies over time.

3. What are the key factors that affect the accuracy of N-Body Gravity Simulation?

The accuracy of N-Body Gravity Simulation depends on several factors, including the precision of the numerical methods used, the number of bodies in the system, and the time step size. Other factors that can affect accuracy include the initial conditions of the system, any external forces acting on the bodies, and the use of approximations or simplifications in the simulation.

4. Can N-Body Gravity Simulation be used to predict real-world events?

While N-Body Gravity Simulation can accurately model the gravitational interactions between bodies in a system, it is not able to make precise predictions about real-world events. This is because there are many other factors, such as atmospheric drag, magnetic fields, and collisions, that can affect the motion of objects in the real world and are not accounted for in the simulation.

5. What are some applications of N-Body Gravity Simulation?

N-Body Gravity Simulation has a wide range of applications in both scientific research and entertainment. It is commonly used in astrophysics to study the formation and evolution of planetary systems, galaxies, and other celestial objects. It is also used in video games and visual effects to create realistic depictions of space and gravity. Additionally, N-Body Gravity Simulation has been used to study the dynamics of biological systems, such as the movement of cells and microorganisms.

Similar threads

  • Classical Physics
Replies
7
Views
744
  • Programming and Computer Science
Replies
19
Views
2K
  • Introductory Physics Homework Help
Replies
4
Views
2K
  • Introductory Physics Homework Help
Replies
5
Views
3K
  • Other Physics Topics
Replies
12
Views
3K
  • High Energy, Nuclear, Particle Physics
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
Replies
1
Views
525
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Programming and Computer Science
Replies
7
Views
2K
Back
Top