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 Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by