clear
Cx(1) = 15;
Cs(1) = 7;
V(1) = 50;
So = 325;
tf = 1:0.06:990;
Vfer = 100;
Co(1) = 7.54;
Ce(1) = 0;
F(1)= 0;
Fa = 100;
td = 1;
kLao(1) = 0;
a = 0;
Ke = 0.1;
Ko = 9.6e-5;
Ki = 3.5;
Ks = 0.612;
Yoxxs = 0.585;
Yredxs = 0.05;
Yos = 0.3857;
Yeo = 1.1236;
Yes = 0.4859;
Yxe = 0.7187;
Yoxcs = 0.5744;
Yredcs = 0.462;
Yce = 0.645;
Qemax = 3.967e-3;
Qomax = 4.25e-3;
Qsmax = 0.04905;
Qm = 5e-4;
ucr = 3.5e-3;
So = 325;
Coo = 0.006;
AR = 12.56;
dV = 0;
dCs(1) = 0;
dCo(1) = 0;
dCe(1) = 0;
dCx(1) = 0;
for t = 1:length(tf)-1
Qs(t+1) = Qsmax*Cs(t)/(Ks+Cs(t))*(1-exp(-t/td));
Qolim(t+1) = Qomax*Co(t)/(Ko+Co(t))*Ki/(Ki+Ce(t));
Qslim(t+1) = ucr/Yoxxs;
A = Qolim(t+1)/Yos;
Qsox(t+1) = min(min(Qs(t+1),Qslim(t+1)),A);
Qsred(t+1) = Qs(t+1)-Qsox(t+1);
Qeup(t+1) = Qemax*(Ce(t)/(Ke+Ce(t)))*(Ki/(Ki+Ce(t)));
B = (Qolim(t+1)-Qsox(t+1)*Yos)*Yeo;
Qeox(t+1) = min(Qeup(t+1),B);
Qepr(t+1) = Qsred(t+1)*Yes;
u(t+1) = (Qsox(t+1)*Yoxxs)+(Qsred(t+1)*Yredxs)+(Qeox(t+1)*Yxe);
Qc(t+1) = (Qsox(t+1)*Yoxcs)+(Qsred(t+1)*Yredcs)+(Qeox(t+1)*Yce);
Qo(t+1) = (Qsox(t+1)*Yos)+(Qeox(t+1)*Yeo);
RQ(t+1) = Qc(t+1)/Qo(t+1);
F(t+1) = F(t)*exp(a-t);
dCs(t+1) = (F(t+1)/60/V(t)*(So-Cs(t)))-(((u(t+1)/Yoxxs)+(Qepr(t+1)/Yes)+Qm)*Cx(t));
dCo(t+1) = (-Qo(t+1)*Cx(t))+(kLao(t)/60*(Coo-Co(t)))-(F(t+1)/60/V(t)*Co(t));
dCe(t+1) = ((Qepr(t+1)-Qeox(t+1))*Cx(t))-(F(t+1)/60/V(t)*Ce(t));
dCx(t+1) = (u(t+1)*Cx(t))-(F(t+1)/60/V(t)*Cx(t));
dV(t+1) = F(t+1)/60;
kLao(t+1) = (113*(Fa/60/AR)^0.25)/60;
Cs(t+1) = Cs(t)+dCs(t+1)*0.06;
Co(t+1) = Co(t)+dCo(t+1)*0.06;
Ce(t+1) = Ce(t)+dCe(t+1)*0.06;
Cx(t+1) = Cx(t)+dCx(t+1)*0.06;
V(t+1) = V(t)+dV(t+1)*0.06;
end
whos
figure(1)
clf
hold on
plot(tf,Ce,'b')
plot(tf,Co,'r')
plot(tf,Cs,'g')
plot(tf,Cx,'y')
legend('Ce','Co','Cs','Cx')
figure(2)
clf
hold on
plot(tf,Qs,'b')
plot(tf,Qslim,'y')
plot(tf,Qsox,'g')
plot(tf,Qsred,'r')
legend('Qs','Qslim','Qsox','Qsred')