Lotka-Volterra Predatir Prey Model Code

2 vues (au cours des 30 derniers jours)
Khushi Patel
Khushi Patel le 25 Sep 2020
Commenté : Khushi Patel le 25 Sep 2020
I used this code for the equation below however i kept getting multiple errors. Any help on this would be appreciated
Script Window:
function [dPdt] = lotkavolterra(t,P)
alpa = 1.5;
beta = 1;
gamma = 3;
delta = 1;
x = P(1);
y = P(2);
dPdt = zeros(2,1);
dPdt(1) = alpha*x - beta*x*y;
dPdt(2) = delta*x*y - gamma*y;
end
Command Window:
tspan = [0, 20];
P0 = [10, 5];
[t,P] = ode45(@(t,P)lotkavolterra(t,P),tspan,P0);
Errors:
Error using alpha
Too many output arguments.
Error in lotkavolterra (line 12)
dPdt(1) = alpha*x - beta*x*y;
Error in @(t,P)lotkavolterra(t,P)
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

Réponse acceptée

Rafael Hernandez-Walls
Rafael Hernandez-Walls le 25 Sep 2020
using this:
function [dPdt] = lotkavolterra(t,P)
alpha = 1.5; % you have error here: you using alpa
beta = 1;
gamma = 3;
delta = 1;
x = P(1);
y = P(2);
dPdt = zeros(2,1);
dPdt(1) = alpha*x - beta*x*y;
dPdt(2) = delta*x*y - gamma*y;
end
  1 commentaire
Khushi Patel
Khushi Patel le 25 Sep 2020
Oh. Thank you so much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dialog Boxes dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by