Lotka-Volterra Predatir Prey Model Code

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

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by