[SciPy-Dev] ode and odeint callable parameters

Jonathan Stickel jjstickel at gmail.com
Tue Jan 19 11:14:14 EST 2016


I also find this inconsistency to be annoying. Probably the result of of 
two different contributors that were unaware of each other. One 
workaround is to do something like the following:

def dfdt(t, f, [args]): # for ode
     [your dfdt function statements]
     return [dfdt]

def dfdt_odeint(f,t, *args): # swap t and f for odeint
         return dfdt(t,f, *args)

so at least you only need to define your ode function just once. As 
shown, it doesn't resolve your tuple issue, but perhaps you could do 
that too (I tend to use lists/arrays rather than tuples when possible).

Perhaps a new keyword flag could be added to odeint to implement 
functions calls the same as ODE. This would avoid breaking backward 
compatibility.

Regards,
Jonathan


On 1/19/16 08:49 , Irvin Probst wrote:
> Hi,
> maybe my question has been asked a thousand times but why are the
> callable's parameters in ode and odeint reversed ?
>
>  From scipy.integrate.ode:
> http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.integrate.ode.html#scipy.integrate.ode
>      f : callable f(t, y, *f_args)
>
>  From scipy.integrate.odeint:
> http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.integrate.odeint.html
> func : callable(y, t0, ...)
>
> Admittedly one will usually choose ode or odeint depending on what has
> to be done, but from an educational point of view this is really annoying.
> Say you want to show how to use ode or odeint to simulate something ?
> You have to define twice the same dynamics:
>
>
> def f_odeint(y,t):
>      return y[1], -np.sin(y[0])
>
> def f_ode(t,y):
>      return [[y[1], -np.sin(y[0])]]
>
> Then come the usual questions:
> - why do I have to reverse y and t ? => Err... you see... because...
> - why can't I return a tuple in f_ode as in f_odeint ? => see ticket #1187
>
> So I know that reversing the callable's parameters will break half the
> code using ode or odeint in the world and this is out of question, but
> couldn't it be possible to make it a bit more clear somewhere in the doc
> that the parameters are indeed reversed ? Or maybe am I missing some
> obvious explanation ?
>
> Regards.
>
>
>
>
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at scipy.org
> https://mail.scipy.org/mailman/listinfo/scipy-dev
>



More information about the SciPy-Dev mailing list