global mu_H Y_H Ks X_BH teta mu_Hmax T Ss_in
mu_Hmax=0.15;
mu_Hmax=mu_Hmax*((1.072)^(T-20));
T=22.6;
X_BH=2295;
teta=1.25;
Y_H=0.6;
Ks=250;
Ss_in=1127;
Sinr=round(Ss_in*0.5/10)*10:10:round(Ss_in*1.5/10)*10;
tspan=0:140;
tm=[0 30 32 34 36 50 52 57 59 61 63 65 72 75 76 79 83 85 87 89 96 99 106 109 116 118 121 124 125 126 127 131 133 134 135 136 137 140];
Ss_in=ones(length(tspan),1)*Ss_in;
res=zeros(length(tm),length(Sinr));
for i=1:length(tm)
for j=1:length(Sinr)
Ss_in(tm(i):end)=Sinr(j);
ode45(@substrate,tspan,Ss_in)
res(i,j)=sqrt((Ss(tm(i)+1)-Sm(i))^2);
end
[minres, lmin]=min(res(i,:));
Ss_in(tm(i):end)=Sinr(lmin);
end
xlabel('Time (day)')
ylabel('Concentrations (mg/L)')
legend ('Substrate')
clear i j
Sp=zeros(length(tm),1);
for i=1:length(tm)
Sp(i)=Ss(tm(i)+1);
end
RMSE=sqrt(sum((Sp-Sm).^2));
function Derivative = substrate(t,Ss)
global mu_H Y_H Ks X_BH teta Ss_in
Derivative =-mu_H/Y_H*(Ss/(Ks+Ss))*X_BH+(1/teta)*(Ss_in(round(t+1))-Ss);
Derivative=Derivative(:);
end