Initialization


In [15]:
import numpy
from matplotlib import pyplot

In [18]:
posLT = numpy.array([[1,0],[0.5,0.5],[0,1],[-0.5,0.5]])
N = len(posLT[:,0])

In [10]:
print(posLT)
print(posLT[0])
print(posLT[:,0])


[[ 1.   0. ]
 [ 0.5  0.5]
 [ 0.   1. ]
 [-0.5  0.5]]
[ 1.  0.]
[ 1.   0.5  0.  -0.5]

Code


In [25]:
# Plot the position of the moon in the rest frame of the earth

pyplot.figure(figsize=(10,6))
pyplot.grid(True)
pyplot.xlabel('$x$')
pyplot.ylabel('$y$')
pyplot.plot(posLT[:,0],posLT[:,1], 'b-', label='RK4')
pyplot.title('Position of the moon in the rest frame of the earth')
pyplot.legend();
pyplot.show();


TODO: explain the break


In [22]:
# Compute the parameters a,b,e

for i in range(1,N-1):
    if (posLT[i+1,0]>=posLT[i,0] and posLT[i,0]<posLT[i-1,0]):
        maxX = posLT[i,0]
        break
        
for i in range(1,N-1):
    if (posLT[i+1,0]<=posLT[i,0] and posLT[i,0]>posLT[i-1,0]):
        maxX = posLT[i,0]
        break
        
for i in range(1,N-1):
    if (posLT[i+1,1]>=posLT[i,1] and posLT[i,1]<posLT[i-1,1]):
        maxX = posLT[i,1]
        break
        
for i in range(1,N-1):
    if (posLT[i+1,1]<=posLT[i,1] and posLT[i,1]>posLT[i-1,1]):
        maxX = posLT[i,1]
        break
        
a = abs(maxX-minX)/2
b = abs(maxY-minY)/2
e = numpy.sqrt(1-b**2/a**2)

In [23]:
# Compute the period

for i in range(2,N-1):
    if (posLT[i+1,0]>=posLT[i,0] and posLT[i,0]<posLT[i-1,0]):
        T = i*dt
        break

In [ ]: