Modeling Lotka-Volterra using ode23
2 views (last 30 days)
Show older comments
I have a question like this. I wonder if my code is correct.
The Lotka-Volterra predator-prey model :
dx/dt =px−qxy
dy/dt =rxy−sy
where x(t) and y(t) are the prey and predator population sizes at time t, and p,q, r, and s are biologically determined parameters. Consider p = 0.4, q = 0.4, r = 0.02, s =2.0, x(0) = 100, y(0) = 8.
function prey
%Predator-prey Model
clc;clear;
y0 = [100;8];
soln = ode23(@f2,[0 100],y0)
t = linspace(0,30,60);
y(:,1)=deval(soln,t,1); %Prey
y(:,2)=deval(soln,t,2); %Predator
figure
plot(t,y(:,1),'-o',t,y(:,2),'--');
hold on;grid on;
legend('Prey','Predator');
xlabel('Time');
ylabel('Population');
hold off;
end
%Predator-prey function
function dxdt = f2(t,x)
dxdt = [0;0];
p =0.4; q = 0.4; r = 0.02; s = 2.0;
dxdt(1) = p*x(1)-q*x(1)*x(2);
dxdt(2) = r*x(1)*x(2)-s*x(2);
end
0 Comments
Accepted Answer
Torsten
on 8 Apr 2016
The code looks ok to me. Why do you ask ? Are the results not as expected ?
Best wishes
Torsten.
0 Comments
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!