In [37]:
import scipy.integrate as integrate
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
def derivativesFunction(inputstate, timespan):
x, y, z, xdot, ydot, zdot = inputstate
mu = 398600.0 # km^3/sec^2
rmag = np.sqrt(x**2.0 + y**2.0 + z**2.0)
#print 'rmag, inputstate', rmag, inputstate
derivs = [xdot,
ydot,
zdot,
-mu*x/rmag**3.0,
-mu*y/rmag**3.0,
-mu*z/rmag**3.0]
#print 'derivs', derivs
return derivs
timespan = np.linspace(0, 10800.0, 10800.0) # start, stop, numpoints # seconds
stateinit = [-3410.673, 5950.957, -1788.627, 1.893006, -1.071993, -7.176346] # km and km/s
statesOverTime = integrate.odeint(derivativesFunction, stateinit, timespan)
x, y, z, xdot, ydot, zdot = statesOverTime.T
#print statesOverTime
#print timespan, x
# plt.plot(phi, u)
afig, ax = plt.subplots()
ax.plot(timespan, x)
#ax.plot(x, y, z)
#ax.set_aspect('equal')
plt.grid(True)
plt.show()
fig3D = plt.figure()
ax3D = fig3D.add_subplot(111, projection='3d')
ax3D.plot(x, y, z)
ax3D.set_aspect('equal')
In [5]:
import scipy.integrate as integrate
import matplotlib.pyplot as plt
import numpy as np
pi = np.pi
sqrt = np.sqrt
cos = np.cos
sin = np.sin
def deriv_z(z, phi):
u, udot = z
return [udot, -u + sqrt(u)]
phi = np.linspace(0, 7.0*pi, 2000)
zinit = [1.49907, 0]
z = integrate.odeint(deriv_z, zinit, phi)
u, udot = z.T
# plt.plot(phi, u)
afig, ax = plt.subplots()
ax.plot(1/u*cos(phi), 1/u*sin(phi))
ax.set_aspect('equal')
plt.grid(True)
plt.show()
In [16]:
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
mpl.rcParams['legend.fontsize'] = 10
fig = plt.figure()
ax = fig.gca(projection='3d')
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
ax.plot(x, y, z, label='parametric curve')
ax.legend()
plt.show()
In [5]:
In [ ]: