% Example 18-2: Conversion Using Dispersion, PFR, CSTR and Tank-in-series Model
%

Per=7.5;
k=0.25;
n=4.35;
tau=linspace(0,20,100);
tiledlayout(1,2)
for i=1:100
Da1(i) = tau(i)*k;
q(i) = sqrt(1 + 4*Da1(i)/Per);
a(i) = (4*q(i)*exp(Per/2));
b(i) = (1 + q(i)).^2.*exp(Per*q(i)/2) -(1 - q(i)).^2.*exp(-Per*q(i)/2);
Xdispersion(i) = 1 - a(i)/b(i);
XPFR(i) = 1 - exp(-tau(i)*k);
XTIS(i) = 1 - (1/((1 + (tau(i)/n)*k)^n));
XCSTR(i) = tau(i)*k/ (1 + tau(i)*k);
Cadis(i)=(1-Xdispersion(i));
CaPFR(i)=(1-XPFR(i));
CaTIS(i)=(1-XTIS(i));
CaCSTR(i)=(1-XCSTR(i));
end
set (gcf,'Position',[0,0.1,800,300])
nexttile
plot(tau,Xdispersion(1:100),tau,XPFR(1:100),tau,XTIS(1:100),tau,XCSTR(1:100),'LineWidth',2)
xlabel('Space time, \tau (mins)')
ylabel(' Conversion')
leg=legend('X_{Dispersion}','X_{PFR}','X_{TIS}','X_{CSTR}');
leg.ItemTokenSize=[10,10];
axis([0 20 0 1])
title('Conversion Profile')
grid on
nexttile
plot(tau,Cadis(1:100),tau,CaPFR(1:100),tau,CaTIS(1:100),tau,CaCSTR(1:100),'LineWidth',2)
xlabel('Space time, \tau (mins)')
ylabel(' Concentration')
leg=legend('C_{Dispersion}','C_{PFR}','C_{TIS}','C_{CSTR}');
leg.ItemTokenSize=[10,10];
axis([0 20 0 1])
title('Concentration Profile')
grid on

%