# Homework Help: Mean anomaly as a function of the true anomaly elliptical orbits

1. May 16, 2013

### Dustinsfl

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 (Text):

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()

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 [Broken]

#### Attached Files:

• ###### pfquestion.png
File size:
41.3 KB
Views:
140
Last edited by a moderator: May 6, 2017
2. May 17, 2013

### TSny

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: May 17, 2013
3. May 17, 2013

### Dustinsfl

With some help of stackoverflow, I was able to implement your suggestion of arctan2 and it works as intended now.

4. May 17, 2013

Good.