Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Order of calculations solar system model

  1. Dec 5, 2015 #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?
     
  2. jcsd
  3. Dec 5, 2015 #2

    Mark44

    Staff: Mentor

    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?
     
  4. Dec 5, 2015 #3
    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.
     
  5. Dec 5, 2015 #4
    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.
     
  6. Dec 5, 2015 #5
    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.
     
  7. Dec 5, 2015 #6
    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.
     
  8. Dec 5, 2015 #7

    jedishrfu

    Staff: Mentor

    Your choice of ODE solver could be the issue. Euler is usually the worst for periodic motion. What one are you using?
     
  9. Dec 5, 2015 #8
    I'm using velocity verlet, meant to be good for orbital motion I read.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Order of calculations solar system model
  1. Modeling and simulaton (Replies: 5)

Loading...