Created
July 19, 2013 14:38
-
-
Save Opiprog/6039573 to your computer and use it in GitHub Desktop.
Solving ODE in Python
This file contains 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 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