Modeling Lotka-Volterra using ode23

24 ビュー (過去 30 日間)
Jovos
Jovos 2016 年 4 月 8 日
回答済み: Torsten 2016 年 4 月 8 日
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 Center および File ExchangeParticle & Nuclear Physics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by