% MATLAB file used in the solution of Example_29_2 of "A First Course on
% Kinetics and Reaction Engineering."
%
function Example_29_2
    % Known Constants
    CAa = 2.5; % mol/L
    VFR = 100.0; % L/min
    Ta = 38.0 + 273.15; % K
    nDa = 0.0; % mol/min
    nUa = 0.0; % mol/min
    % Calculated constants
    nAa = CAa*VFR;
    
    % CSTR first
    display('Case with CSTR first');
    % calculate the CSTR outlet values
    [nAb, nDb, nUb, Tb] = Example_29_2_cstr(nAa,nDa,nUa,Ta);
    % calculate the PFR outlet values
    [nAc, nDc, nUc, Tc] = Example_29_2_pfr(nAb, nDb, nUb, Tb);
    % calculate and report overall conversion and yield
    percent_conversion = 100*(nAa - nAc)/nAa
    sel_D_per_U = nDc/nUc

    % PFR first
    display('Case with PFR first');
    % calculate the PFR outlet values
    [nAb, nDb, nUb, Tb] = Example_29_2_pfr(nAa,nDa,nUa,Ta);
    % calculate the CSTR outlet values
    [nAc, nDc, nUc, Tc] = Example_29_2_cstr(nAb, nDb, nUb, Tb);
    % calculate overall conversion and yield
    percent_conversion = 100*(nAa - nAc)/nAa
    sel_D_per_U = nDc/nUc

end % of Example_29_2.m

