I am trying to use odeint but I have a parameter that changes values with every time step. My function is:
def f(y, t, k1, k2, Pr): return k1*(Pr-k2)*y Where Pr is a pandas series that contains float values, of which I have observed values. And t is a list of integer years from 1961 to 2014. I wrote the following code for odeint:
y0 = 120000 k1 = 0.2 k2 = -.4 y = odeint(f, y0, t, args = (k1, k2, Pr, )) But it gives the following error:
RuntimeError: The size of the array returned by func (54) does not match the size of y0 (1).
k1andk2are overwritten in the first two lines of your function, so the values you're passing in for them are discarded.Prandt? e.g. Pandas DataFrame or Series. Or a simplified example showing their instantiation. It's important for getting the right syntax for working with them.y0is a singleint, whereas the return value offcontains 54 elements. These two must have the same shape. If the initial value is the same for all 54 elements, then simply writey0 = 1.2e5 * np.ones(54).