4

I found the following simulation of an orbit given the semi-major axis of the ellipse, eccentricity, initial velocity, the mass of the object being orbited, and initial position of the orbiting satellite.

The program basically starts off with the following initial conditions:

$$ h \to stepSize\\ a \to semiMajorAxis\\ e \to eccentricity\\ g \to GM/a\\ \vec{X_0} = (a(1+e), 0, 0)\\ \vec{V_o} = (0, \sqrt{\frac{g(1-e)}{(1+e)}},0) $$

Given these initial conditions, the next state is calculated as follow:

$$ \vec{X_{temp}} = \vec{X_0} + (\frac h2)\vec{V_0}\\ r^3 \to (\sqrt{x_0^2 + y_o^2})^3\\ \vec{Acc_{temp}} = \frac{-GM}{r^3}(\vec{X_{temp}})\\ \vec{V_1} = \vec{V_0} + h*\vec{Acc_{temp}}\\ \vec{X_1} = \vec{X_{temp}} + \frac h2 \vec{V_1}\\ $$

The approximations continue accordingly with accuracy increasing for smaller stepSize values.

Assuming I presented this in a way that makes sense, my question is in regards to my result. Look at my simulation here:

http://zixg.com/orbits/

Take note of the two stationary blue dots. These represent the apogee and perigee of an ellipse with semi-major axis 'a' and eccentricity 'e' (Hence, the sun-like object is centered at a corresponding focal point). So it seems that this method doesn't approximate the initial ellipse at all, but rather results in a orbital trajectory that is much larger than the initially assumed ellipse. I'm not sure what to make of this?

Max Hutchinson
  • 3,051
  • 16
  • 29
  • I certainly had trouble figuring out where to stick this one. Perhaps that is the best place? Anyone else? –  May 29 '13 at 19:18
  • Whatever you do, don't crosspost. Flag for migration instead. –  May 29 '13 at 19:19
  • Done, I flagged it with a message requesting appropriate migration. Thanks –  May 29 '13 at 20:05

1 Answers1

3

Looking at your code:

var v = new Array(0, Math.sqrt((g*(1-e))/1+e), 0);

You seem to be missing a set of parenthesis around (1+e). Should be:

var v = new Array(0, Math.sqrt((g*(1-e))/(1+e)), 0);
Max Hutchinson
  • 3,051
  • 16
  • 29