Lotka-Volterra Predatir Prey Model Code
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Khushi Patel
el 25 de Sept. de 2020
Comentada: Khushi Patel
el 25 de Sept. de 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);
0 comentarios
Respuesta aceptada
Rafael Hernandez-Walls
el 25 de Sept. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!