Holooly Plus Logo

Question 10.11: The predator-prey problem. (Using MATLAB's built-in function......

The predator-prey problem. (Using MATLAB’s built-in function to solve a system of two first-order ODEs.)

The relationship between the population of lions (predators), N_{L}, and the population of gazelles (prey), N_{G}, that reside in the same area can be modeled by a system of two ODEs. Suppose a community consists of N_{L} lions (predators) and N_{G} gazelles (prey), with b and d representing the birth and death rates of the respective species. The rate of change (growth or decay) of the lion (L) and gazelle populations can be modeled by the equations:

\begin{aligned}& \frac{d N_{L}}{d t}=b_{L} N_{L} N_{G}-d_{L} N_{L}  & (10.173)\\& \frac{d N_{G}}{d t}=b_{G} N_{G}-d_{G} N_{G} N_{L}\end{aligned}

Determine the population of the lions and gazelles as a function of time from t=0 to t=25 years, if at t=0, N_{G}=3000, and N_{L}=500. The coefficients in the model are: b_{G}=1.1 \mathrm{yr}^{-1}, b_{L}=0.00025 \mathrm{yr}^{-1}, d_{G}=0.0005 \mathrm{yr}^{-1}, and d_{L}=0.7 \mathrm{yr}^{-1}.

The 'Blue Check Mark' means that either the MATLAB code/script/answer provided in the answer section has been tested by our team of experts; or the answer in general has be fact checked.

Learn more on how do we answer questions.

Script File

In this problem N_{L} and N_{G} are the dependent variables, and t is the independent variable. To solve the problem a user-defined function named PopRate (t, N) is written. The function, listed below, calculates the values of \frac{d N_{L}}{d t} and \frac{d N_{G}}{d t} in Eq. (10.173). The input argument \mathrm{N} is a vector of the dependent variables, where N(1)=N_{L} and N(2)=N_{G}. Notice how these components are used when the values of the differential equations are calculated. The output argument dNdt is a column vector where the first element is the value of the derivative \frac{d N_{L}}{d t}, and the second is the value of the derivative \frac{d N_{G}}{d t}

function dNdt = PopRate(t, N)

bG = 1.1; bL = 0.00025 ; dG = 0.0005 ; dL = 0.7;

f1 = bL*N(1)*N(2) - dL*N(1) ;

f2 = bG*N(2) - dG*N(2)*N(1) ;

dNdt = [fl ; f2] ;

The system of ODEs in Eq. (10.173) is solved with MATLAB's solver ode45. The solver uses the user-defined function PopRate for calculating the right-hand sides of the differential equations. The following MATLAB program in a script file shows the details. Notice that \mathrm{Nin} i is a vector in which the first element is the initial value of N_{L} and the second element is the initial value of N_{G}.

tspan = [0  25] ;

Nini= [500  3000] ;

[Time Pop] = ode4 5 ( @PopRa te , tspan, Nini) ;

plot(Time,Pop(:,1) ,'-' ,Time,Pop(:,2) ,'--')

xlabel('Time (yr)')

ylabel('Population')

legend('Lions' ,'Gazelles')

In the output arguments of the solver ode45 , the variable \mathrm{T} ime is a column vector, and the variable Pop is a two-column array, with the solution of N_{L} and N_{G} in the first and second columns, respectively. The first few elements of [Time Pop] that are displayed in the Command Window (if the semicolon at the end of the command is removed) are shown below. The program generates a plot that shows the population of the lions and gazelles as a function of time.

Time =

           0
0.0591
0.1182
0 .1773

Pop =

1.0e+003 *
0.5000        3.0000
0.5020        3.1545
0.5053         3.3166

10.11

Related Answered Questions