Skip to content

Instantly share code, notes, and snippets.

@Opiprog
Created July 19, 2013 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Opiprog/6039573 to your computer and use it in GitHub Desktop.
Save Opiprog/6039573 to your computer and use it in GitHub Desktop.
Solving ODE in Python
from scipy.integrate import odeint
from pylab import * # for plotting commands
def deriv(y,t): # return derivatives of the array y
a = -2.0
b = -0.1
return array([ y[1], a*y[0]+b*y[1] ])
time = linspace(0.0,10.0,1000)
yinit = array([0.0005,0.2]) # initial values
y = odeint(deriv,yinit,time)
figure()
plot(time,y[:,0]) # y[:,0] is the first column of y
xlabel('t')
ylabel('y')
show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment