I am trying to plot elliptical orbits using python. Using formula r=a(1-e^2)/(1+ecos(theta)). The data points needed to be plotted are:
- values of a: 0.39, 0.72, 1.00, 1.52
- values of e: 0.205, 0.007, 0.017, 0.093
- values of theta (Degrees): 77.5, 132, 103, 336
Here is my code so far:
import numpy as np
import matplotlib.pyplot as plt
def radius(r,deg,rad):
a=np.array([0.39,0.72,1.00,1.52])
e=np.array([0.205,0.007,0.017,0.093])
deg=np.array([77.5,132,103,336])
rad=(deg*np.pi)/180
r=(a*(1-e**2))/(1+e*np.cos(rad))
return r,deg,rad
plt.polar(rad, r)
plt.show()
The error I seem to get is NameError: name 'r' is not defined. Since I returned the function I don't understand why it is not defined.