I would like to plot a function of e and nu, where e is the eccentricity and nu the true anomaly. I am only looking at elliptical orbits so 0<e<1. However, when I try to plot them against each other, I have a shape error:
ValueError: operands could not be broadcast together with shapes (10) (5000)
I know this is because I only want 10 spaces for the eccentricity, but is there a way around this?
import numpy as np
e = np.arange(0, 1, 0.1)
vvals = [[] for i in range(len(e))]
nu = np.linspace(0, 2 * np.pi, 5000)
for i in e:
for j in nu:
i = float(i)
j = float(j)
v = np.sqrt(e ** 2 + 2 * e * np.cos(nu) + 1)
i = int(i)
vvals[i].append(v)
for i in e:
pylab.plot(nu, vvals[i])
pylab.show()
forloops are really wonky, to the point where I am not strictly sure what you are trying to do here.v = np.sqrt(e ** 2 + 2 * e * np.cos(nu) + 1)and has nothing to do withmatplotlibandnumpyin behaving correctly.ehas shape (10) andnuhas shape (5000)., so numpy can't figure out what you want to happen that gets fed to thesqrt. Neither can I. What calculation are you trying to do in this line?