% Example 18-1: Concentration and Conversion Profiles for Dispersion and Reaction in a Tubular Reactor
%

k=0.25;
tau=5.15;
Pe=7.5;
Da1 = k*tau;
q = (1 + 4*Da1/Pe)^0.5;
den1 = (1 + q)^2*exp(Pe*q/2);
den2 = (1 - q)^2*exp(-Pe*q/2);
lambda=linspace(0,1,100);
for i=1:100
num(i) = (exp(Pe*lambda(i)/2)*2*((1 + q)*exp(Pe*q/2*(1 - lambda(i))) - (1 - q)*exp(Pe*q/2*(lambda(i) - 1))));
Conc(i) = num(i)/(den1 - den2);
ConcPFR(i) = exp(-Da1*lambda(i));
X(i) = 1 - Conc(i);
XPFR(i) = 1 - exp(-Da1*lambda(i));
end
tiledlayout(1,2)
set (gcf,'Position',[0,0.1,1000,400])
nexttile
plot(lambda,Conc(1:100),lambda,ConcPFR(1:100),'LineWidth',2)
xlabel('Dimensionless distance, \lambda=z/L')
ylabel('Dimensionless Concentration, \psi=C_A/C_{A0}')
leg=legend('Reactor with dispersion','PFR');
leg.ItemTokenSize=[10,10];
axis([0 1 0 1])
title('Dimensionless Concentration Profile')
grid on
nexttile
plot(lambda,X(1:100),lambda,XPFR(1:100),'LineWidth',2)
xlabel('Dimensionless distance, \lambda=z/L')
ylabel('Conversion,X')
leg=legend('Reactor with dispersion','PFR');
leg.ItemTokenSize=[10,10];
axis([0 1 0 1])
title('Conversion Profile')
grid on

%