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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

CamilleC
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


_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: Computing derivatives with scipy.integrate.odeint

gyro-3
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



_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: Computing derivatives with scipy.integrate.odeint

CamilleC
Thanks very much! It's now clear for me.
Camille

Le 28/05/2015 14:24, Gyro Funch a écrit :

> 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
>
>
>
> _______________________________________________
> SciPy-User mailing list
> [hidden email]
> http://mail.scipy.org/mailman/listinfo/scipy-user

_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user