# [SciPy-user] Difficulties with integrate.odeint

Nils Wagner nwagner at mecha.uni-stuttgart.de
Tue Nov 15 02:35:33 CST 2005

 Hi all,

I am going to integrate a set of ordinary differential equations

\dot(z} = P(t) z     , z(t=0) = z_0

with integrate.odeint.

The matrix P(t) varies periodically with period T, P(t) = P(t+T).

def v(t,omega_0,v_0):

return v_0*sin(omega_0*t)

def vp(t,omega_0,v_0):
return v_0*omega_0*cos(omega_0*t)

def P(t):
#
# Periodically varying system matrix
# P(t+T) = P(T)
#
tmp=zeros((2*(n-1),2*(n-1)),Float)
tmp[:n-1,n-1:] = identity(n-1)
tmp[n-1:,:n-1] =
-vp(t,omega_0,v_0)*MinvK_1-v(t,omega_0,v_0)**2*MinvK_2-MinvK_3-MinvK_4
tmp[n-1:,n-1:] = -v(t,omega_0,v_0)*MinvG
return tmp

def F(z,t):
return dot(P(t),z)

z,infodict = integrate.odeint(F, z0, t,full_output=1)

lsoda--  at current t (=r1), mxstep (=i1) steps
taken on this call before reaching tout
in above message,  i1 =       500
in above message,  r1 =  0.2849206026085E-01
Excess work done on this call (perhaps wrong Dfun type).
Run with full_output = 1 to get quantitative information.

The output of infodict is

>>> infodict
{'nfe': array([        756,           0,           0,
0,           0,
1087514384,  1177877182, -1058152689,  1835251574,  1090228948,
-534120349, -1057872112,  1177877180,  1087233807,  1842801181,
-1058126336, -2070079459,  1089984242,          80,
80]), 'nje': array([         24,           0,           0,
0,           0,
1079201176,  -952557537,  1081298328,  1948672715,  1023763292,
-952557537, -1066185320,  -952557538, -1068282472, -1370358758,
1081140197,  -952557538,  1079201176,           0,
49]), 'tolsf': array([  2.41898232e+001,   0.00000000e+000,
4.33528912e-005,
-6.11764773e+004,   1.12941277e+005,  -7.43530547e+004,
1.52941193e+004,  -6.20000134e+004,   9.76471574e+004,
1.69759663e-312,   3.39519327e-313,   8.55589578e-314,
2.23445150e-312,   9.91680933e+000,   0.00000000e+000,
4.99646000e+005,  -1.28205663e+005,   5.11999116e+005,
-7.15518276e+005,   1.69759663e-312]), 'nqu': array([
5,           0,           0,           0,           0,
1076090224,          32,         105,   138113336,   136892392,
48,           8,  1076466816,          81,  1076090288,
1076090288, -1742606915, -1064103817,  1076283023,
1081461165]), 'lenrw': 116, 'tcur': array([  2.84920603e-002,
0.00000000e+000,  -4.25338500e+005,
1.70135427e+006,  -2.83559045e+006,   1.70135427e+006,
-4.25338567e+005,   1.70135427e+006,  -2.41025188e+006,
1.69759663e-312,   2.40966029e+006,  -1.70342483e+006,
4.25930155e+005,  -1.69898792e+006,   2.83559045e+006,
-1.70372062e+006,   4.24746979e+005,  -1.69928371e+006,
2.41084347e+006,   1.69759663e-312]), 'hu': array([
6.05099624e-005,   0.00000000e+000,   2.41898193e+001,
2.78290221e+002,   8.55842102e-015,  -2.78290221e+002,
-6.95725552e+001,   2.43503943e+002,   6.95725552e+001,
3.24665356e-312,   9.91790963e+000,   6.77647660e+004,
-1.69411915e+004,   6.77647660e+004,  -1.12941277e+005,
6.77647660e+004,  -1.69411915e+004,   6.77647660e+004,
-9.60000852e+004,   1.55437997e-312]), 'imxer': 1077570368,
'leniw': 26, 'tsw': array([  1.46187823e-003,   0.00000000e+000,
0.00000000e+000,
-6.06373313e+004,   1.12044275e+005,  -7.38157991e+004,
1.51593328e+004,  -6.14609855e+004,   9.68849425e+004,
1.69759663e-312,  -7.19575108e+005,   5.01006985e+005,
-1.25045833e+005,   5.13361798e+005,  -8.44620941e+005,
5.00183330e+005,  -1.28340450e+005,   5.12538144e+005,
-7.16280491e+005,   1.69759663e-312]), 'message': 'Excess work
done on this call (perhaps wrong Dfun type).', 'nst': array([
500,          0,          0,          0,          0,
1161229464, 1162010880, 1076222336, 1076222048, 1162010944,
1162000288, 1162000328, 1162010976, 1076623264, 1162011008,
1162000368, 1162011040, 1076506496, 1162000408, 1162011072]),
'mused': array([          2,           0,           0,
0,           0,
1087505788, -1712838703, -1058169942,  1740837064,  1090214596,
-920046736, -1057880708, -1712838705,  1087216554, -1989227584,
-1058143585,   344329165,  1089972047,          80,          80])}

Any idea how to resolve the problem ?

Nils

infodict -- a dictionary of optional outputs:
'hu'    : a vector of step sizes successfully used for each time step.
'tcur'  : a vector with the value of t reached for each time step.
(will always be at least as large as the input times).
'tolsf' : a vector of tolerance scale factors, greater than 1.0,
computed when a request for too much accuracy was detected.
'tsw'   : the value of t at the time of the last method switch
(given for each time step).
'nst'   : the cumulative number of time steps.
'nfe'   : the cumulative number of function evaluations for eadh
time step.
'nje'   : the cumulative number of jacobian evaluations for each
time step.
'nqu'   : a vector of method orders for each successful step.
'imxer' : index of the component of largest magnitude in the
weighted local error vector (e / ewt) on an error return.
'lenrw' : the length of the double work array required.
'leniw' : the length of integer work array required.
'mused' : a vector of method indicators for each successful time step: