I have my position and velocity vectors, and also the mass and position of the sun. I need to convert my vectors to the Keplerian Orbit elements, but I can't get a definite number when I do. The orbit isn't changing, yet the 'constant' values I'm calculating are.
I've been reading this and others such as this.
I first calculate the angular momentum with $\vec{h} = \vec{r} \times \vec{v}$. This value changes as the planet goes around the orbit.
Then I calculate the eccentricity with $$\vec{e} = \frac{(v^2-\mu /r)\vec{r}-(\vec{r} \cdot \vec{v})\vec{v}}{\mu}$$
But this changes between 0.9 and 1.1 as the planet orbits, which as far as I'm aware, shouldn't happen. What is going wrong? Perhaps I'm missing something, but surely the calculations I have say that the orbit changes from an ellipse to a hyperbola, and back again.
Any help would be appreciated, thanks.