Created
March 22, 2010 11:54
-
-
Save reactormonk/340005 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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