Skip to content

Instantly share code, notes, and snippets.

@reactormonk
Created March 22, 2010 11:54
Show Gist options
  • Select an option

  • Save reactormonk/340005 to your computer and use it in GitHub Desktop.

Select an option

Save reactormonk/340005 to your computer and use it in GitHub Desktop.
from __future__ import division
from numpy import sqrt, linspace
from scipy.integrate import odeint
from pylab import plot, axis, show
# Define the initial conditions for each of the four ODEs
#inic = [0.5,0,0.2,0] # chaotic
#inic = [0.7,0,0,0] # Secondary
#inic = [0,0.2,0.3,0.5] # Primary
E = 0.2
# Times to evaluate the ODEs. 800 times from 0 to 100 (inclusive).
t = linspace(0, 100, 5000)
# The derivative function.
def f(z,time):
""" Compute the derivate of 'z' at time 'time'.
'z' is a list of four elements.
"""
return [
z[2] + z[1],
z[3] - z[0],
- Vx(z[0], z[1]) + z[3],
- Vy(z[0], z[1]) - z[2]
]
def Vx(x,y):
"""Compute the derivative of the potential by x"""
return (E * (-1 + E + x))/((-1 + E + x)**2 + y**2)**(3/2) + ((1 - E) * (E + x))/((E + x)**2 + y**2)**(3/2)
def Vy(x,y):
"""Compute the derivative of the potential by y"""
return (E * y)/((-1 + E + x)**2 + y**2)**(3/2) + ((1 - E) * y)/((E + x)**2 + y**2)**(3/2)
# Compute the ODE
res = odeint(f, inic, t)
# Plot the results
plot(res[:,0], res[:,1])
axis('equal')
show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment