Graph can not show correct point

조회 수: 1 (최근 30일)
Carey n'eville
Carey n'eville 2020년 12월 28일
편집: Mischa Kim 2020년 12월 28일
Dear friends, I have code below but when I run the code, it gives me this graph. But it should colour the graph at point x=10, x=20 and x=40. I guess it shift and there is a problem. How could I fix it?
CODE:
XS0=[2, 1000];
tspan = [0 40];
[t,XS]=ode45(@BSfunction, tspan, XS0);
figure
hold on
plot(t,XS(:,1),t,XS(:,2))
plot(t(1:10),XS(1:10,1),'r',t(10+1:20),XS(10+1:20,1),'b', t(20+1:end),XS(20+1:end,1),'g')
xlabel('time (year)')
ylabel('Concentration (mg/L)')
function dXSdt=BSfunction(~,XS)
X = XS(1); S = XS(2);
X0=2;
Sin=1000;
So=0;
S0=So+Sin;
V=20;
TH=40;
ko=0.2;
kd=0.01;
Ks=150;
Y=0.5;
S=S0-((ko/Y)*X0*TH);
biomassgrowth=((ko*S*X)/(Ks+S))-(kd*X);
substratutilize = -((ko/Y)*X0);
dXSdt = [biomassgrowth; substratutilize];
end

답변 (1개)

Mischa Kim
Mischa Kim 2020년 12월 28일
편집: Mischa Kim 2020년 12월 28일
Hi Carey, ode45() picks its own time steps to do the integration. However, you can prescribe the times at which you want integration results. E.g. use
tspan = linspace(0,40,41);

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by