% Example 18-6: \mathrm{CSTR}\;\mathrm{with}\;\mathrm{Interchange}\;\mathrm{Model}
%

alpha=0.8;
beta=0.1;
k=0.03;
CA0=2;
tau=linspace(0.1,100,200);
for i=1:200
X(i) = (((beta + alpha*tau(i)*k)*(beta + (1 - alpha)*tau(i)*k)) -beta^2)/(((1 + beta + alpha*tau(i)*k)*(beta + (1 - alpha)*tau(i)*k))-beta^2);
CA(i)=CA0*(1-X(i));
XCSTR(i) = tau(i)*k/(1 + tau(i)*k);
CACSTR(i) = CA0*(1 - XCSTR(i));
end
tiledlayout(1,2)
set (gcf,'Position',[0,0.1,1000,400])
nexttile
plot(tau,CA(1:200),tau,CACSTR(1:200),'LineWidth',2)
xlabel('Space time, \tau (min)')
ylabel('Concentration (kmol/m^3)')
leg=legend('C_A (Model)','C_A (Ideal CSTR)');
leg.ItemTokenSize=[10,10];
axis([0 100 0 2])
title(' Concentration Profile')
grid on
nexttile
plot(tau,X(1:200),tau,XCSTR(1:200),'LineWidth',2)
xlabel('Space time, \tau (min)')
ylabel('Conversion,X')
leg=legend('X (Model)','X (Ideal CSTR)');
leg.ItemTokenSize=[10,10];
axis([0 100 0 1])
title('Conversion Profile')
grid on

%