% MATLAB file used in the solution of Example 14.3 of 
% "A First Course on Kinetics and Reaction Engineering."

% Data provided in the problem statement, in consistent units
T=568.0 + 273.15; % K
P0=1.0; % atm
Diam=0.325; % cm
L=240; % cm
y0 = [8	10	22	42	66	74	88]'; % mol % cyclopropane
y0 = y0/100; % mol fraction cyclopropane
Vfr = [2.91	4.31	2.94	2.05	4.16	2.62	3.49]'; % cm3(stp)/s
y = [7.6	9.7	21.1	39.5	63.4	70.3	84.5]'; % mol % cyclopropane
y = y/100; % mol fraction cyclopropane

% Other known constants
Rgas=82.06; % cm^3 atm / (K mol)
Pstp = 1; % atm
Tstp = 273.15; % K
% Calculate x and y using equations (14) and (19) from the solution
x = (-pi()*Diam^2/4)*(P0/Rgas/T)*(y0 + y)/2;

y_hat = zeros(7,1);
for i = 1:7
    y_hat(i) = (Pstp*Vfr(i)/Rgas/Tstp)*(y(i) - y0(i))/L;
end

% Use the MATLAB script file "FitLinmSR.m" from "A First Course on
% Kinetics and Reaction Engineering" to fit a straight line through the
% origin to the data.
FitLinmSR