% MATLAB file used in the solution of part (c) of Example 13.1 of 
% "A First Course on Kinetics and Reaction Engineering."

% Data provided in the problem statement, in consistent units
V=1.7; % L
tau=8.5; % min
CA0=[0.10 0.25 0.30 0.48 0.65 0.79 0.93 1.00 1.33 1.50 1.68 2.00]'; % mol/L
CZ0=[0.75 0.37 0.19 0.61 2.48 3.07 0.09 3.39 1.27 1.70 1.94 0.47]'; % mol/L
fA=[9.93E-03 6.93E-03 4.95E-03 8.92E-03 1.81E-02 1.98E-02 3.61E-03 2.09E-02 1.28E-02 1.53E-02 1.59E-02 8.08E-03]';

% Calculate x and y of the linearized model equation
xa = -V*CA0.*(1-fA);
CZ = (2*CZ0 + CA0.*fA)/2;
x = xa.*CZ;
y_hat = (-V/tau)*CA0.*fA;

% 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

