Lotka-Volterra Predatir Prey Model Code
조회 수: 2 (최근 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);
댓글 수: 0
채택된 답변
Rafael Hernandez-Walls
2020년 9월 25일
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 Center 및 File 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!