% MATLAB file used in the solution of Example 35.1 of "A First Course on 
% Kinetics and Reaction Engineering."
%
function Example_35_1
    % Known quantities and constants
    T = 450 + 273.15; % K
    P = 5; % atm
    VFR_FS1 = 200 * 0.02832; % m^3/h
    yA_FS1 = 0.15;
    
    % Universal Constants
    Rpv = 0.08206E-3; % m3 atm/(mol K)
    
    % Additional Calculated Constants
    ntot_FS1 = P*VFR_FS1/Rpv/T; % mol/h, ideal gas law
    nA_FS1 = yA_FS1*ntot_FS1; % mol/h
    
    % Set up storage for the plot
    q_R2 = linspace(0.0,0.25);
    fA = zeros(length(q_R2),1);
    
    % Generate the data for the plot
    for i = 1 : length(q_R2)
        % Model the two reactors
        z1 = Example_35_1_PFR('R1',q_R2(i));
        z2 = Example_35_1_PFR('R2',q_R2(i));
        % Calculate and save the overall conversion
        fA(i) = 100*(nA_FS1 - (z1(1) + z2(1)))/nA_FS1;
    end
    
    % Create the plot
    plot(100*q_R2,fA)
    xlabel('Percent of Flow to Low Density Bed')
    ylabel('Conversion (%)')

end % of Example_35_1.m
