Clear Filters
Clear Filters

Lotka-Volterra Predatir Prey Model Code

2 views (last 30 days)
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);

Accepted Answer

Rafael Hernandez-Walls
Rafael Hernandez-Walls on 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

More Answers (0)

Categories

Find more on Numerical Integration and 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!