subploting an interspecific competition predation model with global varoables in matlab

To subplot an interspecific competition predation model with global variables in Matlab, you can follow the steps below:

  1. Define the global variables that you want to use in your simulation, for example:
main.m
global r a e1 e2 b1 b2 K1 K2
r = 0.2; % growth rate of the first species
a = 0.1; % per capita effect of the second species on the first species
e1 = 0.8; % conversion efficiency of the first species
e2 = 0.9; % conversion efficiency of the second species
b1 = 0.1; % per capita predation rate of the second species on the first species
b2 = 0.2; % per capita predation rate of the first species on the second species
K1 = 100; % carrying capacity of the first species
K2 = 100; % carrying capacity of the second species
521 chars
10 lines
  1. Define the differential equations of the model using the global variables, for example:
main.m
function dydt = competition_predation(t,y)
global r a e1 e2 b1 b2 K1 K2
dydt = zeros(2,1);
dydt(1) = r*y(1)*(1-y(1)/K1) - a*y(2)*y(1)/(1+b1*y(1)) + e1*b2*y(2)*y(1)/(1+e1*b2*y(1));
dydt(2) = r*y(2)*(1-y(2)/K2) - a*y(1)*y(2)/(1+b2*y(2)) + e2*b1*y(1)*y(2)/(1+e2*b1*y(2));
end
273 chars
7 lines
  1. Define the initial conditions for the simulation, for example:
main.m
y0 = [50; 50]; % initial population sizes of the two species
61 chars
2 lines
  1. Set the time span for the simulation, for example:
main.m
tspan = [0 200]; % time span of the simulation
47 chars
2 lines
  1. Use the "ode45" solver to solve the differential equations and plot the results using subplots, for example:
main.m
[t,y] = ode45(@competition_predation, tspan, y0);
figure;
subplot(2,1,1);
plot(t,y(:,1),'r',t,y(:,2),'b');
legend('Species 1','Species 2');
xlabel('Time');
ylabel('Population size');
title('Interspecific competition');
subplot(2,1,2);
plot(y(:,1),y(:,2),'k');
xlabel('Species 1');
ylabel('Species 2');
title('Predation');
322 chars
14 lines

This will give you a figure with two subplots: the first one shows the population sizes of the two species over time, and the second one shows the predation relationship between the two species.

gistlibby LogSnag