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

AI Thread Summary
The discussion focuses on simulating N-body gravity interactions in a computational physics program. The user successfully modeled gravity from a single body but struggles to accurately compute the net gravitational force when multiple bodies are involved. They initially attempted to sum the gravitational forces from each body, which led to incorrect results. The equations provided for force, acceleration, velocity, and position updates are shared, but the user seeks guidance on properly implementing the calculations for multiple gravitational influences. The challenge lies in correctly summing the forces while accounting for the interactions between all bodies involved.
DrCheeto
Messages
2
Reaction score
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
Can anyone help me?
 
TL;DR Summary: I came across this question from a Sri Lankan A-level textbook. Question - An ice cube with a length of 10 cm is immersed in water at 0 °C. An observer observes the ice cube from the water, and it seems to be 7.75 cm long. If the refractive index of water is 4/3, find the height of the ice cube immersed in the water. I could not understand how the apparent height of the ice cube in the water depends on the height of the ice cube immersed in the water. Does anyone have an...
Thread 'Variable mass system : water sprayed into a moving container'
Starting with the mass considerations #m(t)# is mass of water #M_{c}# mass of container and #M(t)# mass of total system $$M(t) = M_{C} + m(t)$$ $$\Rightarrow \frac{dM(t)}{dt} = \frac{dm(t)}{dt}$$ $$P_i = Mv + u \, dm$$ $$P_f = (M + dm)(v + dv)$$ $$\Delta P = M \, dv + (v - u) \, dm$$ $$F = \frac{dP}{dt} = M \frac{dv}{dt} + (v - u) \frac{dm}{dt}$$ $$F = u \frac{dm}{dt} = \rho A u^2$$ from conservation of momentum , the cannon recoils with the same force which it applies. $$\quad \frac{dm}{dt}...

Similar threads

Back
Top