# Simulating Gravitational Interactions in a Particle System

• Python
• Jozefina Gramatikova
In summary, In order to create the solar system, you need to create a System of Particles, each with its own field. You need to use the Euler's Method to calculate the accelerations for all the particles.
Jozefina Gramatikova
I have a project to make the solar system. I am trying to start from somwhere. On the notes it says that we need to start by creating a System of Particles
• Two-body simulation (Circular motion)
• Implement Gravitational acceleration
Each particle (planet) could have its own field.
• I.e. Each particle loops over all the other bodies to get the effect of all the other fields on it.
• Extend to three body system
Need to create all accelerations in one step before updating the positions and velocities.
I have to use the Euler's method.

I have my code from last week where we had to simulate a projectile with constant acceleration.
Here is my code:
Python:
import numpy as np

class Particle:

position = np.array([0,0,0])
velocity = np.array([0,0,0])
acceleration = np.array([0,0,0])

def __init__(self, initialPosition, initialVelocity, initialAcceleration, Name, mass):
self.position = initialPosition
self.velocity = initialVelocity
self.acceleration = initialAcceleration
self.Name = Name
self.mass = mass

def update(self, deltaT):
self.position = self.position + self.velocity*deltaT
self.velocity = self.velocity + self.acceleration*deltaT
def __repr__(self):
return 'Particle: %10s, Mass: %.5e, Position: %s, Velocity: %s, Acceleration:%s'%
(self.Name,self.mass,self.position, self.velocity,self.acceleration)
Pls help!

This is not a trivial request. Have you done some research with Google?

There are many examples of similar problems solved with Python that you could look at and learn how to write your own.

QuantumQuest
I have done my research. I am sorry, but couldn't find something like this.

What exactly do you need help with?
Is your sim not doing what it's supposed to?

OK, that is a good beginning for a particle. But a particle in a gravitational field, does not have a constant acceleration. The acceleration experienced by a particle of mass $m$ under the influence of an external force $F$, is given by the 2nd law of Newton:
$\vec{a} = \vec{F}/m$
The force your particle will experience will be the gravitational one from the other particle 2, and will be the gravitational law:
$\vec{F}= -\frac{G m_1 m_2}{|r_1-r_2|^2} \hat{r_{12}} = -\frac{G m_1 m_2}{|\vec{r_1} - \vec{r_2}|^3} (\vec{r}_1 - \vec{r}_2)$, (where $\hat{r_{12}}$ the unit vector pointing from the particle 2>1).

and so you can see that the force depends on the relative distance between the particle 1 and 2 (and so it's not constant). Start from defining a way to measure the distance between your particles then. That distance can be used to determine the vector of acceleration per unit of time and the latter will affect the movement of your particles.

## 1. How can we program the movements of celestial bodies in the Solar System?

To program the movements of celestial bodies in the Solar System, we use mathematical models and algorithms based on the fundamental laws of physics, such as Newton's laws of motion and gravity. These models take into account the mass, position, and velocity of each object in the Solar System and calculate their trajectories over time.

## 2. What programming languages are commonly used for simulating the Solar System?

Programming languages such as Python, Java, and C++ are commonly used for simulating the Solar System. These languages have libraries and frameworks that make it easier to implement complex mathematical calculations and simulations.

## 3. How accurate are the simulations of the Solar System?

The accuracy of simulations of the Solar System depends on the complexity of the model and the data used. With advanced models and high-quality data, simulations can be accurate to within a few kilometers.

## 4. Can we use programming to predict future celestial events in the Solar System?

Yes, programming can be used to predict future celestial events in the Solar System, such as planetary alignments, eclipses, and comet sightings. By simulating the movements of celestial bodies over time, we can forecast these events with a high degree of accuracy.

## 5. How is programming the Solar System beneficial to scientific research?

Programming the Solar System allows us to study and understand the complex dynamics of celestial bodies in our Solar System. It also enables us to make predictions and simulations for future events, providing valuable insights for scientific research and space exploration.

• Programming and Computer Science
Replies
10
Views
10K
• Programming and Computer Science
Replies
2
Views
2K
• Classical Physics
Replies
19
Views
2K
• Introductory Physics Homework Help
Replies
18
Views
1K
• Programming and Computer Science
Replies
7
Views
2K
• Programming and Computer Science
Replies
1
Views
3K
• Classical Physics
Replies
15
Views
2K
• Programming and Computer Science
Replies
1
Views
2K
• Astronomy and Astrophysics
Replies
6
Views
2K
• Engineering and Comp Sci Homework Help
Replies
2
Views
2K