Order of calculations solar system model

AI Thread Summary
The discussion revolves around coding a solar system model in Java, focusing on Earth, the Sun, and Mercury. The user is experiencing instability in the planetary movements, which they suspect may stem from the incorrect handling of velocities and the center of mass. It is clarified that in a center-of-mass frame, the center of mass should remain stationary with zero velocity, and recalculating it after each time step is unnecessary unless mass changes occur. The Sun's movement does influence the planets due to gravitational interactions, but it does not have a defined orbit around the center of mass. The choice of the velocity Verlet method for integration is noted as appropriate for orbital motion, but potential numerical errors should be minimized to maintain stability.
whatisreality
Messages
286
Reaction score
1
I am really, really stuck! I am trying to write java code to model the solar system, or at least currently just earth, the sun and mercury. I've made a big mistake somewhere, the planets are very unstable and either move in a line or spiral inwards! I just wanted to check that I'm doing things in the right order, I have so many loops.

I've set the sun to start at the origin, and the Earth's position is
$$x = 1.496 \times 10^{11}m$$ and Mercury is at $$x = 5.971 \times 10^{10}m$$

I want everything to be done in the centre of mass frame, so I then calculate the position of the centre of mass and subtract it from the initial positions, e.g. so the sun is at x - centreOfMass.
The velocity of each body is given by $$v = \frac{2\pi r}{T}$$ This is probably where I go wrong. I know the orbital period of mercury and Earth around the sun, so I can calculate their velocities around the centre of mass. But the sun will also move, even if only a tiny, tiny bit, and I don't have its orbital period around the centre of mass! So how can I work out its velocity?

Assuming I have the sun's velocity around the centre of mass, I then work out the velocity of the centre of mass. Because I want to stay in the centre of mass frame, I then subtract this velocity from the velocities of the planets.

My code is then written so that the position is recalculated, given a time step, then the centre of mass position is recalculated and subtracted from the new position. A new velocity for each planet is calculated, then the centre of mass velocity is recalculated and again subtracted from each velocity.

Is this the correct procedure? Do I need to recalculate the centre of mass position/velocity after each time step, or is that the problem?
 
Technology news on Phys.org
whatisreality said:
I've set the sun to start at the origin, and the Earth's position is
##x = 1.496 \times 10^{11}m## and Mercury is at ##x = 5.971 \times 10^{10}m##
Your choice of x for a variable suggests that the planets are located along a one-dimensional line. How are you representing the positions of the planets? In the plane of their orbits you can represent the position of each with two coordinates. Are you using rectangular or polar coordinates for each position?

Also, the orbits of the planets are ellipses. Are you assuming that they are traveling in circular orbits?
 
Mark44 said:
Your choice of x for a variable suggests that the planets are located along a one-dimensional line. How are you representing the positions of the planets? In the plane of their orbits you can represent the position of each with two coordinates. Are you using rectangular or polar coordinates for each position?

Also, the orbits of the planets are ellipses. Are you assuming that they are traveling in circular orbits?
Yes, I've assumed circular orbits. And my mistake, I am using x and y, just setting all y to zero at the start. Sorry, should have made that clear.
 
whatisreality said:
I am really, really stuck! I am trying to write java code to model the solar system, or at least currently just earth, the sun and mercury. I've made a big mistake somewhere, the planets are very unstable and either move in a line or spiral inwards! I just wanted to check that I'm doing things in the right order, I have so many loops.

I've set the sun to start at the origin, and the Earth's position is
$$x = 1.496 \times 10^{11}m$$ and Mercury is at $$x = 5.971 \times 10^{10}m$$

I want everything to be done in the centre of mass frame, so I then calculate the position of the centre of mass and subtract it from the initial positions, e.g. so the sun is at x - centreOfMass.
The velocity of each body is given by $$v = \frac{2\pi r}{T}$$ This is probably where I go wrong. I know the orbital period of mercury and Earth around the sun, so I can calculate their velocities around the centre of mass. But the sun will also move, even if only a tiny, tiny bit, and I don't have its orbital period around the centre of mass! So how can I work out its velocity?

Assuming I have the sun's velocity around the centre of mass, I then work out the velocity of the centre of mass. Because I want to stay in the centre of mass frame, I then subtract this velocity from the velocities of the planets.

My code is then written so that the position is recalculated, given a time step, then the centre of mass position is recalculated and subtracted from the new position. A new velocity for each planet is calculated, then the centre of mass velocity is recalculated and again subtracted from each velocity.

Is this the correct procedure? Do I need to recalculate the centre of mass position/velocity after each time step, or is that the problem?

You are doing everything in the centre of mass frame, so the center of mass is always in the centre of that frame. Its velocity is zero by definition. It can change only if a new mass enters the system or the mass of an element changes.

The Sun does not have an orbit around the center of mass. It has an unpredictable path that depends on the orbits of the planets. The planets have elliptical orbits with one focus the centre of mass. They don't care where the sun moves as long as there is no collision.

This should simplify what you are doing quite a bit.
 
Hornbein said:
You are doing everything in the centre of mass frame, so the center of mass is always in the centre of that frame. Its velocity is zero by definition. It can change only if a new mass enters the system or the mass of an element changes.

The Sun does not have an orbit around the center of mass. It has an unpredictable path that depends on the orbits of the planets. The planets have elliptical orbits with one focus the centre of mass. They don't care where the sun moves as long as there is no collision.

This should simplify what you are doing quite a bit.
So I don't need to recalculate the centre of mass position and velocity every time? According to my code, it changes a little bit though. Should I add the centre of mass velocity onto all other velocities to stay in its frame?

EDIT: Any movement of the sun does affect the planets though, surely. The only force on the planets(for my purposes) is gravity, and the position of and distance from the sun affects the direction of that gravity.
 
whatisreality said:
So I don't need to recalculate the centre of mass position and velocity every time? According to my code, it changes a little bit though. Should I add the centre of mass velocity onto all other velocities to stay in its frame?

By definition it can't change in a center-of-mass frame. There is an error creeping in somewhere. It could be anything, so it's hard to say how to get rid of it. If it is roundoff error then you can't get rid of it, you just have to minimize it. Somehow or other you've got to patch up the error so that the center of mass remains in the center of the frame with velocity zero. This cannot change.

Adding it to the other velocity vectors definitely will not work. I think you meant subtraction.

You have to try to prevent the errors from feeding on themselves so that they increase exponentially.
 
Your choice of ODE solver could be the issue. Euler is usually the worst for periodic motion. What one are you using?
 
jedishrfu said:
Your choice of ODE solver could be the issue. Euler is usually the worst for periodic motion. What one are you using?
I'm using velocity verlet, meant to be good for orbital motion I read.
 

Similar threads

Back
Top