numerical solution of predator-prey model

1 Ansicht (letzte 30 Tage)
ahed salman
ahed salman am 8 Okt. 2019
Kommentiert: Stephan am 8 Okt. 2019
Hello all, I have a 3d predator prey system and i want to solve it numerically in order to analyze it, I am new to Matlab, used it couples of time before and i beg you for help as i am writing my thesis now, below is the code i used but it seems not to work and i have errors i do not understant in order to fix! Please Help!!!
function signal
%initial conditions
x0=1; y0=1; z0=1;
IC=[x0,y0,z0];
t = 0:.1:60;
r=15;
b=0.05433;
beta=0.9;
rho= .7;
delta= .2;
m= .2;
[t,s]= ode45(@RHS, t,IC );
plot(t ,s(:,2),'linewidth',2,'color','b')
grid on;
xlabel('t', 'FontSize', 20);
ylabel('\omega', 'FontSize', 20);
function dsdt= RHS(t,s)
dsdt_1=r*(s(1)+s(2))-b*s(1)*(s(1)+s(2))-beta*s(1)*s(3)/(1+beta*s(1))-s(1)*(1+s(3)*s(2))/(1+s(3));
dsdt_2=s(1)*(1+s(3)*s(2))/(1+s(3))-b*s(2)*(s(1)+s(2))-rho*beta*s(2)*s(3)/(1+beta*s(2));
dsdt_3=delta*s(1)*s(3)/(1+beta*s(1))+rho*delta*s(2)*s(3)/(1+beta*s(2))-m*s(3);
dsdt=[dsdt_1;dsdt_2,dsdt_3];
end
end

Akzeptierte Antwort

Stephan
Stephan am 8 Okt. 2019
Bearbeitet: Stephan am 8 Okt. 2019
Problem was here:
dsdt=[dsdt_1;dsdt_2,dsdt_3];
it should be:
dsdt=[dsdt_1;dsdt_2;dsdt_3];
Then it works.
function signal
%initial conditions
x0=1; y0=1; z0=1;
IC=[x0,y0,z0];
t = 0:.1:60;
r=15;
b=0.05433;
beta=0.9;
rho= .7;
delta= .2;
m= .2;
[t,s]= ode45(@RHS, t,IC );
plot(t ,s(:,2),'linewidth',2,'color','b')
grid on;
xlabel('t', 'FontSize', 20);
ylabel('\omega', 'FontSize', 20);
function dsdt= RHS(t,s)
dsdt_1=r*(s(1)+s(2))-b*s(1)*(s(1)+s(2))-beta*s(1)*s(3)/(1+beta*s(1))-s(1)*(1+s(3)*s(2))/(1+s(3));
dsdt_2=s(1)*(1+s(3)*s(2))/(1+s(3))-b*s(2)*(s(1)+s(2))-rho*beta*s(2)*s(3)/(1+beta*s(2));
dsdt_3=delta*s(1)*s(3)/(1+beta*s(1))+rho*delta*s(2)*s(3)/(1+beta*s(2))-m*s(3);
dsdt=[dsdt_1;dsdt_2;dsdt_3];
end
end
  6 Kommentare
ahed salman
ahed salman am 8 Okt. 2019
yes, i want to see how x,y,z behave over time
Stephan
Stephan am 8 Okt. 2019
One way would be the usage of subplot, which allows to arrange several plots in one figure. s should be an array of 3 columns (x,y,z) and as many lines as time steps. If you grab the components one by one this could be a propper way to analyze your results.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by