Mean anomaly as a function of the true anomaly elliptical orbits

Click For Summary
The discussion focuses on the calculation of mean anomaly as a function of true anomaly in elliptical orbits, highlighting a discontinuity at π in the graph generated by the function M2evals. The issue arises from the use of the arctan function, which produces principal values that lead to a jump in the output when the angle is in the second or third quadrant. A solution proposed involves using the arctan2 function, which correctly handles the angle and avoids discontinuities. Implementing arctan2 resolves the problem, allowing the graph to behave as expected. The conversation emphasizes the importance of choosing the right mathematical functions in orbital mechanics calculations.
Dustinsfl
Messages
2,217
Reaction score
5
The book Orbital mechanics by Curtis says that the function (I labeled M2evals) is monotonically increasing. However, at pi, I have a discontinuity and the graph jumps below the negative axis when it should continue on; that is, the e = 0 should be the line y = x.

Code:
import pylab
import numpy as np

e = np.arange(0.0, 1.0, 0.15).reshape(-1, 1)
nu = np.linspace(0, 2 * np.pi, 50000)
M2evals = (2 * np.arctan(((1 - e) / (1 + e)) ** 0.5 * np.tan(nu / 2)) -
           e * (1 - e ** 2) ** 0.5 * np.sin(nu) / (1 + e * np.cos(nu)))

fig2 = pylab.figure()
ax2 = fig2.add_subplot(111)

for Me2, _e in zip(M2evals, e.ravel()):
    ax2.plot(nu.ravel(), Me2, label = str(_e))

pylab.legend()
pylab.xlim((0.0, 7.75))
pylab.ylim((-np.pi, np.pi))
pylab.savefig('eccentrueanomfunc.eps', format = 'eps', dpi = 1000)
pylab.show()

Here is the plot:
where the plot jumps down it is supposed to be shifted up to meet the first half.
What is wrong?
http://img96.imageshack.us/img96/5397/pfquestion.png
 

Attachments

  • pfquestion.png
    pfquestion.png
    27.3 KB · Views: 794
Last edited by a moderator:
Physics news on Phys.org
The problem may lie in the arctan function which gives "principle values" as output.

Thus, arctan(tan(x)) does not yield x if x is an angle in the second or third quadrant. If you plot arctan(tan(x)) from x = 0 to x = Pi, you will find that it has a discontinuous jump at x = Pi/2.

I think you can correct for this by using the function arctan2(x1, x2). See http://docs.scipy.org/doc/numpy/reference/generated/numpy.arctan2.html

For your case, instead of writing arctan(arg), I believe you would write arctan2(1, 1/arg) where arg is the argument of your arctan function. That way, when arg becomes negative, arctan2 will yield an angle in the second quadrant rather than the fourth.

I'm not familiar with python, but it appears arctan2 is similar to a function in Mathematica which I have used in similar circumstances.

At least it would be easy to give it a try.
 
Last edited:
  • Like
Likes 1 person
With some help of stackoverflow, I was able to implement your suggestion of arctan2 and it works as intended now.
 
Good.
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
2K