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

% Data provided in the problem statement, in consistent units
V=2.3; % L
T=848.0; % K
P0=1036.0; % Torr
Rgas=62.366; % L-Torr/mol/K
t = [0; 0.1; 0.2; 0.3; 0.4; 0.5; 0.6; 0.7; 0.8; 0.9; 1.0]; % ms
Pz = [0; 121; 202; 275; 336; 375; 417; 416; 433; 457; 476]; % Torr

% Calculate x and y for part (a)
disp('Part (a)');
nA0 = P0*V/Rgas/T;
extent = (V/Rgas/T)*Pz;
nA = nA0 - 2*extent;
x = -t;
y_hat = log(nA/nA0);

figure;
% 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;
title('Part (a)');

% Calculate x and y for part (b) and fit a straight line through the origin
% to the resulting data
disp('Part (b)');
x = t/V;
y_hat = (1./nA - 1/nA0);
figure
FitLinmSR;
title('Part (b)');