Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB: In the Lotka Volterra predator-prey model, the changes in the predator p

ID: 2322877 • Letter: M

Question

MATLAB: In the Lotka Volterra predator-prey model, the changes in the predator population y and the prey population x are described by the following equations: delta x(t) = x(t+1) - x(t) = a*x(t) - b*x(t)*y(t) delta y(t) = y(t+1) - y(t) = c*x(t)*y(t) - d*y(t) Write a function simulatepredatorprey(x,y, a,b,c,d, T) that takes in the initial population sizes of x and y and simulates the model with the input parameters, for T discrete time steps (in years), updating the population sizes after each time step. Your function should return the history of the population sizes as a 2-row matrix (first row containing the history of x and second row containing the history of y), starting with the initial population sizes in the first column, and with each additional column containing the population sizes of x and y at that time step.

Explanation / Answer

Copy and paste the flollowing in a MATLAB Script:

function pp=simulatepredatorprey(x,y,a,b,c,d,T)

N=input('Time of the whole simulation (in years) N=');

X(1)=x;

Y(1)=y;

xx=x;

yy=y;

t=T;

i=1;

for n=1:1:N

XX(n)=xx;

YY(n)=yy;

xx=a*XX(n)-b*XX(n)*YY(n)+XX(n);

yy=c*XX(n)*YY(n)-d*YY(n)+YY(n);

if n==t

i=i+1;

X(i)=xx;

Y(i)=yy;

t=t+T;

end

end

pp=[X;Y];

end