How can i resolve this?

Hello, I’m trying of solve this differential equations and graphing them , but i have this errors, and i dont know what I´m doing wrong, could you help me? it´s a predator-prey dinamics

import numpy as np
import matplotlib.pyplot as plt
from numpy import *
from numpy.random import *
from matplotlib.pyplot import *
from scipy.integrate import odeint

#tasa de crecimiento de las presas 
r = 10
a = 1
#tasa de crecimiento de los lobos 
c = 2
#mortalidad de los lobos
m = 2

def depre(t,IR):
    M = IR[1]
    W = IR[2]
    dM= r*M-a*W
    dW = a*M*c-m*W
    dIR = [dM,dW]
    return  dIR

IR0 = [1000,0,11]
t = np.linspace(0,15,1000)
IR = odeint(depre, IR0, t)

M = IR[: , 0]
W = IR[: ,1]

the errors are:

RuntimeError                              Traceback (most recent call last)
<ipython-input-2-aa21044ab78e> in <module>
     17 x0 = [1000, 0, 100]
     18 t = np.linspace(0,15,1000)
---> 19 x = odeint(dep,x0,t)
     21 M = x[:,0]

~\anaconda3\lib\site-packages\scipy\integrate\ 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, tfirst)
    239     t = copy(t)
    240     y0 = copy(y0)
--> 241     output = _odepack.odeint(func, y0, t, args, Dfun, col_deriv, ml, mu,
    242                              full_output, rtol, atol, tcrit, h0, hmax, hmin,
    243                              ixpr, mxstep, mxhnil, mxordn, mxords,

RuntimeError: The size of the array returned by func (2) does not match the size of y0 (3).

You might need to add a little more detail about the errors you have received. If it’s a lesson/project then please also add a link to the relevant section.

1 Like

You are returning an array of size 2 while passing an initial value array of size 3. This issue can be easily resolved if you take x0 = [0,11] instead of x0 = [1000,0,11]; since you are not even using the first element x0[0] anywhere in your function depre.