Skip to content

Instantly share code, notes, and snippets.

@reactormonk
Created May 12, 2010 12:02
Show Gist options
  • Select an option

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

Select an option

Save reactormonk/398495 to your computer and use it in GitHub Desktop.
# 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