[SciPy-User] about ode

Pauli Virtanen pav@iki...
Sun Mar 11 06:14:30 CDT 2012


11.03.2012 03:01, aa kirjoitti:
> can You  give me alitle explanation using scipy escpecially abolut 
> sc.integrate.ode,
> i found matlab code like this:
> g = @(t,x)  [x(1); -2*x(2)]
> [t,x] = ode45(g,[0:1], [1.5,3])
> plot(x(:,1),x(:,2))
> 
> ---
> how to get equivalent code in scipy...??

import numpy as np
from scipy.integrate import odeint

def g(x, t):
    return [x[0], -2*x[1]]

t = np.linspace(0, 1, 200)
x = odeint(g, [1.5, 3], t)   # LSODAR, not Runge-Kutta


See also:

http://stackoverflow.com/questions/9466046/how-to-make-odeint-successful

^ In that recipe, replace 'zvode' by 'dopri5' to get R-K

http://www.scipy.org/NumPy_for_Matlab_Users



More information about the SciPy-User mailing list