- #1
Dustinsfl
- 2,281
- 5
I can't figure out why one of my orbits isn't plotting correctly. Here is first part of the question.
This has already been turned in
A spacecraft is launched from Earth into an orbit about the Sun such that the spacecraft will make
a precisely three orbits in two years; it will thus make a hyperbolic flyby of Earth two years after
the initial launch.
Using the position and velocity information immediately after flyby in problem 3, use your two-
body simulation code developed earlier this semester to calculate and plot the resulting spacecraft
trajectory within the solar system (assuming no further planetary interactions occur). To provide a
reference, include the circular orbits of Earth and Mars on this same plot.I am going to attach a Mathematica notebook that answers all the important info which is extensive. So the notebook is better than typing it all out.
I then used Distance Units ant Time Units to nondimensionalize the speed, distance, and time for Earth, Mars, and elliptical orbit. Earth and Mars are fine.
My elliptical orbit is wrong. There is probably a mistake in solving the problem in the Mathematica file but I don't know what I did wrong.
Below is my python code for the plotting:
Here is a the output:
http://img600.imageshack.us/img600/1580/hw8problem4.png
This has already been turned in
A spacecraft is launched from Earth into an orbit about the Sun such that the spacecraft will make
a precisely three orbits in two years; it will thus make a hyperbolic flyby of Earth two years after
the initial launch.
Using the position and velocity information immediately after flyby in problem 3, use your two-
body simulation code developed earlier this semester to calculate and plot the resulting spacecraft
trajectory within the solar system (assuming no further planetary interactions occur). To provide a
reference, include the circular orbits of Earth and Mars on this same plot.I am going to attach a Mathematica notebook that answers all the important info which is extensive. So the notebook is better than typing it all out.
I then used Distance Units ant Time Units to nondimensionalize the speed, distance, and time for Earth, Mars, and elliptical orbit. Earth and Mars are fine.
My elliptical orbit is wrong. There is probably a mistake in solving the problem in the Mathematica file but I don't know what I did wrong.
Below is my python code for the plotting:
Code:
#!/usr/bin/env python
# This program solves the 3 Body Problem numerically and plots the
# trajectories in non-dimensionalized units
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
from numpy import linspace
from mpl_toolkits.mplot3d import Axes3D
mu = 1.0
# r0 = [-149.6 * 10 ** 6, 0.0, 0.0] # Initial position
# v0 = [29.9652, -5.04769, 0.0] # Initial velocity
# u0 = [-149.6 * 10 ** 6, 0.0, 0.0, 29.9652, -5.04769, 0.0]
u0 = [-1.0, 0.0, 0.0, 0.993545, -0.2, 0.0]
e0 = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0]
m0 = [1.53, 0.0, 0.0, 0.0, 1.23152, 0.0]
def deriv2(e, dt):
n = -mu / np.sqrt(e[0] ** 2 + e[1] ** 2 + e[2] ** 2)
return [e[3], # dotu[0] = u[3]'
e[4], # dotu[1] = u[4]'
e[5], # dotu[2] = u[5]'
e[0] * n, # dotu[3] = u[0] * n
e[1] * n, # dotu[4] = u[1] * n
e[2] * n] # dotu[5] = u[2] * n def deriv(u, dt):
n = -mu / np.sqrt(u[0] ** 2 + u[1] ** 2 + u[2] ** 2)
return [u[3], # dotu[0] = u[3]'
u[4], # dotu[1] = u[4]'
u[5], # dotu[2] = u[5]'
u[0] * n, # dotu[3] = u[0] * n
u[1] * n, # dotu[4] = u[1] * n
u[2] * n] # dotu[5] = u[2] * n def deriv3(m, dt):
n = -mu / np.sqrt(m[0] ** 2 + m[1] ** 2 + m[2] ** 2)
return [m[3], # dotu[0] = u[3]'
m[4], # dotu[1] = u[4]'
m[5], # dotu[2] = u[5]'
m[0] * n, # dotu[3] = u[0] * n
m[1] * n, # dotu[4] = u[1] * n
m[2] * n] # dotu[5] = u[2] * n
dt = np.arange(0.0, 3 * np.pi, .01) # Time to run code in seconds'
u = odeint(deriv, u0, dt)
e = odeint(deriv2, e0, dt)
m = odeint(deriv3, m0, dt)
x, y, z, x2, y2, z2 = u.T
x3, y3, z3, x4, y4, z5 = e.T
x6, y6, z6, x7, y7, z7 = m.T
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(x3, y3, z3)
ax.plot(x, y, z)
ax.plot(x6, y6, z6)
plt.axis((-1.7, 1.7, -1.7, 1.7))
plt.show()
Here is a the output:
http://img600.imageshack.us/img600/1580/hw8problem4.png
Attachments
Last edited by a moderator: