I've just started with Python yesterday, and I'm getting an error using scipy.integrate.odeint.
I've defined a function
def SIR(x, t, beta, gamma, mu, M):
which takes the numpy.array objects x, t, and M; and the scalar floats beta, gamma, and mu.
M is (60,60) in size, but I don't think this matters.
x and t are both nonsingleton, with x.shape being (180,) and t.shape being (5000,). I've tried giving them a singleton dimension, such that they have shapes (180,1) and (5000,1) respectively, but I still get the same error :
In [1]: run measles_age.py
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/IPython/utils/py3compat.py in execfile(fname, *where)
173 else:
174 filename = fname
--> 175 __builtin__.execfile(filename, *where)
/Users/qcaudron/Documents/SIR/measles_age.py in <module>()
111
112
--> 113 x = integrate.odeint(SIR, x0, t, args=(beta, gamma, mu, M));
114
115 # plot(t, x);
/Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages/scipy/integrate/odepack.py in odeint(func, y0, t, args, Dfun, col_deriv, full_output, ml, mu, rtol, atol, tcrit, h0, hmax, hmin, ixpr, mxstep, mxhnil, mxordn, mxords, printmessg)
141 output = _odepack.odeint(func, y0, t, args, Dfun, col_deriv, ml, mu,
142 full_output, rtol, atol, tcrit, h0, hmax, hmin,
--> 143 ixpr, mxstep, mxhnil, mxordn, mxords)
144 if output[-1] < 0:
145 print _msgs[output[-1]]
I get this error even when SIR just returns x, and if I strip all arguments apart from x and t from it :
def SIR(x, t):
return x;
As you can see, the line causing the error is
x = integrate.odeint(SIR, x0, t, args=(beta, gamma, mu, M));
EDIT :
I've been asked to add the full code for the SIR method. Because it's relatively long, I've dropped the full .py script in a pastebin :
http://pastebin.com/RphJbCHN
Thanks again.
SIRshould returndx/dtatt. Is that whatSIRdoes?ximmediately, it's not really relevant - the equation we're solving could well bedx/dt = x, in which case, yes, it's returning the correct calculation. I'm not sure why an "object is too deep for desired array" error is being returned.fortran. Have you tried usingintegrate.ode?