Modeling Lotka-Volterra using ode23

2 次查看(过去 30 天)
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

采纳的回答

Torsten
Torsten 2016-4-8
The code looks ok to me. Why do you ask ? Are the results not as expected ?
Best wishes
Torsten.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by