[SciPy-User] Computing derivatives with scipy.integrate.odeint

Gyro Funch gyromagnetic at gmail.com
Thu May 28 08:24:30 EDT 2015


On 2015-05-28 2:34 AM, Camille Chambon wrote:
> Hello,
> 
> I'm trying to understand how scipy.integrate.odeint works.
> 
> I wrote the following example:
> 
> import numpy as np
> from scipy.integrate import odeint
> y0 = [2]
> def func(y, t):
>     return [y[0]]
> t = np.arange(0, 4.0, 1.0)
> y = odeint(func, y0, t)
> print 'y', y
> 
> It prints:
> y [[  2.        ]
>  [  5.43656382]
>  [ 14.77811278]
>  [ 40.17107594]]
> 
> Why don't I get:
> y [[  2.        ]
>  [  4.]
>  [ 8.]
>  [ 16.]]
> 
> ?
> 
> My question is probably due to my limited knowledge in basic
> mathematics.
> 
> Thanks for your help.
> 
> Camille
> 


Hello Camille,

The way that 'func' is written, you are solving the differential
equation

dy/dt = y ; y(0) = 2 ,

which has the solution y = 2 * e^t.

-gyro






More information about the SciPy-User mailing list