function Activity_11_2b
% MATLAB solution to Example 11.4 of "A First Course on Kinetics and
% Reaction Engineering."
%
% Constants
V = 10; % L
VFR = 10; % L/min
V_impulse = 75/1000; % L
t_bar = V/VFR;

% Experimental data from the table
t = [0
0.02
0.15
0.23
0.35
0.4
0.52
0.58
0.75
0.82
1.02
1.2
1.47
1.75
1.9
2.25
2.49
2.99];

Vt = [0
0.7238
0.6398
0.5808
0.5426
0.5039
0.4297
0.4222
0.3433
0.3187
0.2713
0.2361
0.1543
0.1327
0.1167
0.094
0.0466
0.0312];

% Calculate F using equation (4)
F = zeros(length(t),1);
F(1) = 0.;
for i = 2:length(t)
    F(i) = VFR/100/V_impulse*trapz(t(1:i),Vt(1:i));
end

% Calculate F_CSTR using equation (5), but with more data points so that a
% smooth curve results
t_CSTR = linspace(t(1),t(length(t)));
F_CSTR = zeros(length(t),1);
for i = 1:length(t_CSTR)
    F_CSTR(i) =1-exp(-t_CSTR(i)/t_bar);
end


% Plot the results
figure
plot(t,F,'or',t_CSTR,F_CSTR,'k')
xlabel('Lambda')
ylabel('F(lambda)')
legend('Lab','CSTR')

end % of Activity_11_2b

