[SciPy-user] suggestions for improving scipy.integrate.odeint
Hans Fangohr
H.FANGOHR at soton.ac.uk
Tue Apr 19 13:16:52 EDT 2005
Hi Arnd,
> On Tue, 19 Apr 2005, Hans Fangohr wrote:
>
> [...]
>
>> 1. The initial value (array) can change while odeint carries out the
>> integration. This source code
>>
>> #----------------------------
>> import Numeric
>> from scipy.integrate import odeint
>>
>> def rhs(y,t):
>> return -y[0]
>>
>> y0 = Numeric.array([1.0])
>> print "Initial value:",y0
>> ts = Numeric.arange(0,10,1)
>> ys = odeint( rhs, y0, ts )
>> print "Initial value:",y0
>> #----------------------------
>>
>> produces the following output:
>> #===========================
>> Initial value: [ 1.]
>> Initial value: [ 0.00012341]
>> #===========================
>>
>> I can kind-of-see why this may happen (without digging in the source).
>> However, this is highly confusing to the students because y0 is an input
>> argument to the odeint function and should not change when odeint is
>> called.
>
> I think this is actually done on purpose,
> as y0 contains the last entry of ys,
> print ys[-1]
> [ 0.00012341]
> This allows to restart odeint with this initial value
> to continue the integration.
I can see what you are saying.
However, I would argue that this 'obscure' feature of returning the last
value of ys (indirectly) in y0 is not 'pythonic' because it is not clear
that this would happen.
Note also, that y0 does not change if the type of y0 is a list (!) rather
than an Numeric.array (as in my example). If the intention is that y0 is
always the same as ys[-1] then this should be consistent independent of
the type of y0 (although --- as I said before --- I can't see being a
good idea yet).
> We stumbled across the same some time ago
> (I thought this was documented somewhere, but it seems
> it is not, at least not in the doc-string to odeint).
Correct :)
Thanks for the feedback,
Hans
More information about the SciPy-User
mailing list