N-body simulation - straight line orbits

In summary, the conversation involved a problem with a N-body simulation using Python and Numpy and implementing the Euler-Cromer method. The issue was getting straight orbits that tended towards infinity. The equations used to evaluate the system were provided and the code used was also included. The problem was solved by identifying incorrect initial velocities that were a large fraction of the speed of light, making the gravitational influence of the Sun irrelevant.
  • #1
XanMan
14
1

Homework Statement



The problem is your typical N-body simulation, implemented using Python and Numpy. The implementation specifically calls for using the Euler-Cromer method. For this particular case I used the Sun and the first 4 planets of the solar system.

Essentially the problem is I'm getting straight orbits, tending towards infinity. Attached is an image of the output.

Homework Equations


[/B]
The following are the equations used to evaluate the system :
$$\mathbf{a_i} = \sum^N_{j \neq i} \cfrac{Gm_j}{|\mathbf{R}_{ij}|^3}\mathbf{R}_{ij}$$
$$\mathbf{v_i}(t + \Delta t) = \mathbf{v_i}(t) + \mathbf{a_i}\Delta t$$
$$\mathbf{x_i}(t + \Delta t) = \mathbf{x_i}(t) + \mathbf{v_i}\Delta t$$

The Attempt at a Solution


[/B]
Below is my code (commented as best as I can) - I tried various slight alterations, such as calculating the position first, the the velocity, rather than the other way round - but to no avail!

My suspicion is something related to the acceleration - I simply cannot figure out what. I noticed (after printing 10,000 values!) that as the x-coordinate of a body approaches zero, the y-coordinate simply increases more and more, and never goes below it's previous value. In order words I noticed the following issue with regards to the y-positions (which I cannot understand why or if its actually an issue) :
$$y_n < y_{n+1} \ \text{(always)}$$

Appreciate any help - Cheers!

Python:
import numpy as np

from matplotlib import pyplot as plt

# SECTION I - VARS, DATA STRUCTURES

# Defining Constants
AU = 149.6*(10**9)
G = 6.6743*(10**(-11))
deltaT = 24*3600

# Initializing Planetary Data
# planetary_data = [['name', mass, initial position, initial velocity]]
planetary_data = [['Sun',1.989*(10**30),0*AU,0],
                  ['Mercury',0.330*(10**24),0.387*AU,47.36*(10**6)],
                  ['Venus',4.869*(10**24),0.723*AU,35.02*(10**7)],
                  ['Earth',5.974*(10**24),1*AU,29.78*(10**7)],
                  ['Mars',0.647*(10**24),1.524*AU,24.07*(10**7)]]

# Structures to store vel(ocity) vectors and pos(ition) vectors after one full iteration on all bodies
vel_vectors = np.array([[0,0],
                        [0,0],
                        [0,0],
                        [0,0],
                        [0,0]])

pos_vectors = np.array([[0,0],
                        [0,0],
                        [0,0],
                        [0,0],
                        [0,0]])

# Structures to store temp_vel(ocity) vectors and temp_pos(ition) vectors during calculations
temp_vel_vectors = np.array([[0,0],
                             [0,0],
                             [0,0],
                             [0,0],
                             [0,0]])

temp_pos_vectors = np.array([[0,0],
                             [0,0],
                             [0,0],
                             [0,0],
                             [0,0]])
 

Attachments

  • figure_1.png
    figure_1.png
    14.6 KB · Views: 456
Last edited by a moderator:
Physics news on Phys.org
  • #2
Assuming you use SI base units, your initial velocities are a large fraction of the speed of light (or even above that for Venus). At that speed you won't see a relevant gravitational influence of the Sun.
 
  • Like
Likes XanMan
  • #3
mfb said:
Assuming you use SI base units, your initial velocities are a large fraction of the speed of light (or even above that for Venus). At that speed you won't see a relevant gravitational influence of the Sun.

Much better now - I feel silly for copying those off my assignment sheet without noticing the mistakes! Cheers!
 

Attachments

  • figure_1.png
    figure_1.png
    27.3 KB · Views: 422
  • Like
Likes mfb

FAQ: N-body simulation - straight line orbits

1. What is an N-body simulation?

An N-body simulation is a computational method used in astrophysics and other fields to model the motion of a system of particles, such as stars or planets, interacting with each other through gravitational forces.

2. How does N-body simulation work?

N-body simulation involves solving the equations of motion for each individual particle in the system, taking into account the gravitational forces between all pairs of particles. This is typically done using numerical integration methods, such as the Runge-Kutta algorithm.

3. What are straight line orbits?

Straight line orbits, also known as linear orbits, refer to the paths followed by objects in a system that move in a straight line without deviating from their course. In the context of N-body simulation, this means that the objects in the system are not affected by any external forces, such as drag or friction.

4. Can N-body simulation accurately model real-world systems?

N-body simulation can provide accurate results for simple systems, but it becomes increasingly challenging to accurately model more complex systems with a large number of particles. Real-world systems also involve other factors, such as relativistic effects and collisions, which are not typically accounted for in N-body simulations.

5. What are some applications of N-body simulation?

N-body simulation has a wide range of applications, including studying the dynamics of celestial bodies in astrophysics, predicting the trajectories of spacecraft, and simulating the motion of molecules in chemistry and biology. It is also used in computer graphics to create realistic animations of physical systems.

Similar threads

Replies
6
Views
1K
Replies
3
Views
2K
Replies
6
Views
624
Replies
19
Views
3K
Replies
15
Views
2K
Replies
4
Views
5K
Replies
7
Views
3K
Back
Top