First - my question: After the orbit insertion, in the coast stage, and assuming perigee is out of the atmosphere, and neglecting any external forces and influences - is the orbit now "fixed"? As in, should apogee, perigee, eccentricity and inclination now be fixed values?
A bit of a background:
I am working on a spaceflight simulator FSX SpacePort, and currently, I am implementing cockpit instrumentation. I have a display that shows the location of my spacecraft, as it ascends on a trajectory towards the orbit. The display is dynamic - it shows the orbit's changing shape as the spacecraft progresses towards its intended orbit.
I have implemented an algorithm and pseudo code I found here (using C++), and in this basic form, all works and looks good.
When I reach apogee and try to circularize, and as eccentricity nears 0, I cut out my first stage engines. Because the engines have a bit of a ramp-down time, it is always a bit of a guess when to cut the engines off so that the eccentricity would be as close to 0. I do this manually, and I might put in some algorithm in the future to do this for me.
The problem I have is, after the engines are off and the launch stack is coasting, the parameters of my orbital ellipse keep changing - by a small amount at first, but then, progressively faster, the perigee descends back into atmosphere and I eventually crash into the ground.
I thought that, without any external forces, the orbit is "stable" - the orbital parameters (apoapsis, periapsis, eccentricity...) would be fixed and not changing. Before I check my physics code (which has so far been reliable), I thought I checked first if I fully understood the astrodynamics.
edit: I added the screen caps of the orbital display. The time stamps are at the bottom, the 3 images show the span of about 10 seconds. You can see how, a, b, e, apogee and perigee (values are in km, above ground) are changing... inclination is rock steady. Symbols: - diamond is the spacecraft position - full dot is apogee - hollow dot is perigee - also, "apo" and "per" numerical readouts are flipped, it's a bug...
edit 2: OK - My physics guy looked at my code, and almost immediately saw what I was doing wrong - and it kind of surprised me: I was assuming that my gravitational constant was indeed a constant, at 9.81 m/s^2. At orbital altitudes, it is actually a variable that depends on altitude. I inserted 2 lines of code that properly calculated the g vs. altitude relationship, and sure enough, the values are rock steady, exactly where they should be! So - the problem was in me assuming a "constant" gravitational constant!