You use S in calculating X, so you need to solve them together, not one after the other.
Also ln is log in MATLAB.
Try
XS0=[2, 1000];
tspan = [0 40];
[t,XS]=ode45(@BSfn, tspan, XS0);
figure
hold on
plot(t,XS(:,1),t,XS(:,2))
xlabel('time (year)')
ylabel('Concentration (mg/L)')
legend('Biomass','Substrate','location','southeast')
function dXSdt=BSfn(~,XS)
X = XS(1); S = XS(2);
X0=2;
Sin=1000;
So=0;
S0=So+Sin;
V=10;
TH=40;
ko=0.2;
kd=0.01;
Ks=150;
Y=0.5;
S=-((X0/Y)*ko*TH)+S0-(Ks*log(S/S0));
biomassgrowth=((ko*S*X)/(Ks+S))-(kd*X);
substratutilize = -((ko*X0*S)/(Y*(Ks+S)));
dXSdt = [biomassgrowth; substratutilize];
end
Best Answer