Created
March 29, 2010 13:04
-
-
Save reactormonk/347813 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 = [25,0,0,0.2] | |
| E = 0.2 | |
| # Times to evaluate the ODEs. 800 times from 0 to 100 (inclusive). | |
| t = linspace(0, 2000, 5000) | |
| # The derivative function. | |
| def f(z,time): | |
| """ Compute the derivate of 'z' at time 'time'. | |
| 'z' is a list of four elements. | |
| """ | |
| x, y, p_x, p_y = z | |
| r = (x**2 + y**2)**(1/2) | |
| return [ | |
| 2*p_x*(p_x*x+p_y*y)/r**3, | |
| 2*p_y*(p_x*x+p_y*y)/r**3, | |
| (p_x) - (2 * x * (x * (p_x) + y * (p_y)))/r**3, | |
| (p_y) - (2 * y * (x * (p_x) + y * (p_y)))/r**3 | |
| ] | |
| # 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