[SciPy-User] odeint (python vs mathematica)

Mark P m.perrin at me.com
Wed Feb 10 10:08:29 EST 2010


Hello all,

(my first post to the list)

I have been performing modelling of ionic currents in Mathematica for the past three years as a student. I have recently passed into the hallowed halls of post-grad, and am keen to be done with Mathematica and use a free and open solution for my projects, hence Python and numpy/scipy. 

I've made some progress with the transition; the cookbooks are especially helpful. There is one in particular I have been looking at - the rabbit/fox model ( Lotka-Volterra Tutorial), that is helping me to understand odeint.

=====
from numpy import *
import pylab as p
# Definition of parameters
a = 1.
b = 0.1
c = 1.5
d = 0.75
def dX_dt(X, t=0):
    """ Return the growth rate of fox and rabbit populations. """
    return array([ a*X[0] -   b*X[0]*X[1] ,
                  -c*X[1] + d*b*X[0]*X[1] ]) 

from scipy import integrate

t = linspace(0, 10000,  10000)              # time
X0 = array([10, 5])                     		# initials conditions: 10 rabbits and 5 foxes
X = integrate.odeint(dX_dt, X0, t)
===

A simple form of this code in Mathematica is:

===
a = 1
b = 0.1
c = 1.5
d = 0.75

eqn1 := r'[t] == a * r[t] - b * r[t] * f[t]
eqn2 := f'[t] == -c * f[t] + d * b * r[t] * f[t]

solution = NDSolve[{eqn1, eqn2, r[0] == 10, f[0] == 5}, {r[t], f[t]}, {t, 0, 10000}, MaxSteps -> Infinity]
===

My question is about speed. When computed in Mathematica 7 the code is roughly about 10x faster than odeint (I've increased t from 15 in the cookbook to 10000 to allow the measurement of speed to be made). But I know from the web that numpy/scipy can be of an equivalent or faster speed. I was wondering whether the solution can be sped up; and would that require the use of C or Fortran.

I see the inherent advantage of using Python with numpy/scipy and I do not expect the speeds of a compiled language but I was hoping for equivalent speeds to other interpreted solutions.

Thank you,

Mark Perrin
Electrophysiology Research Fellow
Ottawa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20100210/0e2124a7/attachment.html>


More information about the SciPy-User mailing list