numerical solution of predator-prey model

1 view (last 30 days)
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

Accepted Answer

Stephan
Stephan on 8 Oct 2019
Edited: Stephan on 8 Oct 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 Comments
ahed salman
ahed salman on 8 Oct 2019
yes, i want to see how x,y,z behave over time
Stephan
Stephan on 8 Oct 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots 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!