Question on Matlab Lotka-Volterra Predator-Prey models (Page 119, 2d ed. of Shif
ID: 3209881 • Letter: Q
Question
Question on Matlab
Lotka-Volterra Predator-Prey models (Page 119, 2d ed. of Shiflet;: The Fox and the Rabbit Many dynamic systems are interdependent systems. One such pair of systems is the population of Foxes and Rabbits. As more rabbits are born, there is more food for available for the foxes and therefore the population of the foxes grow. As more foxes hunt the rabbits, there are fewer rabbits available to produce more rabbits reducing the population of the rabbits. The reduction in rabbits therefore causes less food for the foxes which reduces the population of the foxes. This causes a cyclic population of both species. This cyclic system is often referred to as a limit cycle. Using R for rabbits and F for foxes, the differential equation for the Rabbits is given as dR/dt - aR bRF and the differential equation for the foxes is dF/dt- bgRF-hF, where a growth rate of Rabbits, b is the death rate based on encounters between rabbits and foxes, g is the rate of growth based on food source, h is the natural death rate of foxes. Initial population of rabbits 0.8 Initial population of foxes0.8 0.2 0.6 0.25 0.3 Time is in months, use a time step of 0.001 months. Populations are in thousands, i.e. 0.8 is 800. Create a m-file to simulate the population of foxes versus rabbits. Adjust the time of the simulation so that three complete cycles of each population is plotted versus time. Plot the rabbit population in blue and the fox population in red. Include a legend labeling the traces. Be sure to include title and labels with proper units. Paste the commands from your m-file into the box below for grading Remember, mfies should siwas start with the clear command. Before ploting always call and clear the figure tripuretieinExplanation / Answer
% Matlab program to draw population plot.This is similiar to LotkaVolterra PredetorPrey model.
% The results are shown at each time step.
%plotting a time series graph for x(Rabbits) or y(Foxes).
% Set the parameter choice = 1 for a time series plot for x.
% Set choice = 2 for a time series plot for y.
% Equation parameters a,b,g,h
% Equations are solved using a numerical ODE solver.
% =========================================================================
function LotkaVolterra_JA
clear % Clears command window
clc % Clears command history
clf % Removes anything in the figure window before simulation.
% =============== Set choice to 1 or 2 ====================================
choice = 2;
countdown = 5; % Countdown time length before simulation runs.
iterations = 3; % Sets initial interation count to 1;
pausetime = 0.001; % Shows solutions at each time step.
runtime = 10; % Duration time of simulation.
% ================ Equation parameter values ==============================
a=0.2;
b=0.6;
g=0.25;
h=0.3;
% =============== Initial conditions for x and y ==========================
initialx = 800;
initialy = 800;
fprintf('---------------------------------- LotkaVolterra Predetor Prey model Matlab code ----------------------------------')
fprintf(' Parameter values set,')
fprintf(' a = %0.2f b = %0.6f h = %0.25f h = %0.3f ',a,b,g,h)
fprintf(' To plot a time series graph for x, set the choice parameter in the code to 1.')
fprintf(' Set choice to 2 to plot a time series graph for y. Simulation will run in ')
for i = 5:-1:1
fprintf(' %8i',countdown') % Countdown to simulation start.
countdown = countdown-1;
pause(1)
end
% Solves equations using numerical ODE solver 45 (nonstiff runge kutta)
deq1=@(t,x) [x(1)*(a - b*x(2)); -x(2)*(bg-h*x(1))];
[t,sol] = ode45(deq1,[0 runtime],[initialx initialy]);
arraysize = size(t); % Sets time array size for the for loop.
%============ Solutions are plotted at each time step =====================
for i = 1 : max(arraysize)
subplot(2,1,1)
plot(sol(iterations,1),sol(iterations,2),'.','color',[rand; rand; rand],'markersize',14,'MarkerFaceColor','b');
hold on
title(['Lotka-Volterra Equations t = ' num2str(t(iterations))],'fontsize',12)
xlabel('x','fontsize',12)
ylabel('y','fontsize',12)
axis([min(sol(:,1)) max(sol(:,1)) min(sol(:,2)) max(sol(:,2))])
subplot(2,1,2)
text(0.1,0.5,'Time Series graph will be shown at the end of the simulation')
iterations = iterations + 1; % Adds 1 to the iteration count.
pause(pausetime)
end
% ==== Plots time series of x or y graph depending on choice ==============
if choice == 1
subplot(2,1,2)
plot(t(:,1),sol(:,1),'b.','markersize',10,'MarkerFaceColor','b')
title(['Lotka-Volterra time series for x run time = ' num2str(max(t)) ' seconds '],'fontsize',12)
xlabel('t')
ylabel('x')
axis([min(t(:,1)) max(t(:,1)) min(sol(:,1)) max(sol(:,1))])
elseif choice == 2
title(['Lotka-Volterra time series for y run time = ' num2str(max(t)) ' seconds '],'fontsize',12)
subplot(2,1,2)
plot(t(:,1),sol(:,2),'r.','markersize',10,'MarkerFaceColor','r')
title(['Lotka-Volterra time series for y run time = ' num2str(max(t)) ' seconds '],'fontsize',12)
xlabel('t')
ylabel('x')
axis([min(t(:,1)) max(t(:,1)) min(sol(:,2)) max(sol(:,2))])
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.