Skip to content

Instantly share code, notes, and snippets.

@certik certik/t.py

Created Jan 2, 2012
Embed
What would you like to do?
Trajectory
from math import pi, sin, cos
from numpy import array, vstack
from numpy.linalg import norm
from pylab import plot, savefig
R = 10.
M = 1.
G = 1.
phi = 30 * 180. / pi
v0_magnitude = 0.1
r = array([0, 0, R])
v = v0_magnitude * array([cos(pi), 0, sin(pi)])
trajectory = []
dt = 0.1
t = 0
while t < 100:
trajectory.append(r.copy())
a = -G * M * r / norm(r)**3
v += a * dt
r += v * dt
t += dt
trajectory = vstack(trajectory)
plot(trajectory[:, 0], trajectory[:, 2])
savefig("trajectory.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.