Created
May 12, 2010 12:02
-
-
Save reactormonk/398495 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
| # Solution for astrophysics #8.3 | |
| 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,0] | |
| # Times to evaluate the ODEs. 800 times from 0 to 100 (inclusive). | |
| a = linspace(1, 0.01, 1000) | |
| m = 0.27 | |
| g = 0.0 | |
| l = 0.73 | |
| k = 0.0 | |
| # The derivative function. | |
| def f(r, a): | |
| ta = -(m/a + g/a**2 + l*a**2 + k)**-1 | |
| return [ ta, 1/a * ta ] | |
| # Compute the ODE | |
| res = odeint(f, inic, a) | |
| # Plot the results | |
| plot(a, res[:,0]) | |
| plot(a, res[:,1]) | |
| axis('equal') | |
| show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment