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

 채택된 답변

Stephan
Stephan 2019년 10월 8일
편집: Stephan 2019년 10월 8일

0 개 추천

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

ahed salman
ahed salman 2019년 10월 8일
oh thank you very much. Thou, i have one more question if i may. Can you please suggest better way to plot the numerical solution better than the one I used in my code? I would really appreciate it pleeease.
Stephan
Stephan 2019년 10월 8일
what is a better plot for you?
ahed salman
ahed salman 2019년 10월 8일
the plot in my code only plot x along time t, what i need is a plot for the whole system solution in order analyze the system properly
Stephan
Stephan 2019년 10월 8일
So you need to plot 3D data over time?
ahed salman
ahed salman 2019년 10월 8일
yes, i want to see how x,y,z behave over time
Stephan
Stephan 2019년 10월 8일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

질문:

2019년 10월 8일

댓글:

2019년 10월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by