Class date(s):

28 February to 06 March







Textbook references
 F2011: Chapter 7
 F2006: Chapter 5
Suggested problems
F2011

F2006

Problem 77 (a)

Problem 56 (a)

Problem 78 (a)

Problem 57 (a)

Problem 715

Not in this edition

Class materials
28 February 2013 (07C)
04 March 2013 (08A)
06 March 2013 (08B1)
Source code: R
R code for the example covered in class:
t < c(0, 50, 100, 150, 200, 250) # [minutes]
# or you can write t < seq(0, 250, 50)
CA < c(154, 114, 87, 76, 70, 58) # [mol/m^3]
# Plot the data first. See the expected trend. It it decreasing nonlinearly, so it is either first or second order (but not zeroth order)
plot(t, CA)
grid()
# Assume it is a first order, rA = k CA
# So plot log(CA0/CA) against t
plot(t, log(CA[1]/CA))
grid()
# Does not quite look like a straight line, but let us fit a leastsquares model anyway
mod.first < lm( log(CA[1] / CA) ~ t + 0) # force intercept to be zero
summary(mod.first)
#Call:
#lm(formula = log(CA[1]/CA) ~ t + 0)
#
#Residuals:
# 1 2 3 4 5 6
# 1.874e16 8.988e02 1.493e01 7.361e02 5.502e02 7.784e02
#
#Coefficients:
# Estimate Std. Error t value Pr(>t)
#t 0.0042174 0.0002555 16.51 1.49e05 ***
#
#Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
#Residual standard error: 0.09474 on 5 degrees of freedom
#Multiple Rsquared: 0.982, Adjusted Rsquared: 0.9784
#Fstatistic: 272.5 on 1 and 5 DF, pvalue: 1.489e05
# Now assume a second order system, rA = k CA^2
# So plot 1/CA against t
plot(t, 1/CA)
grid()
abline(mod.first)
# Definitely more linear. Let us fit the least squares model to check:
mod.second < lm( I(1/CA) ~ t)
summary(mod.second)
#Call:
#lm(formula = I(1/CA) ~ t)
#
#Residuals:
# 1 2 3 4 5 6
#2.751e04 5.219e05 6.146e04 2.227e04 7.051e04 1.951e04
#
#Coefficients:
# Estimate Std. Error t value Pr(>t)
#(Intercept) 6.769e03 3.692e04 18.33 5.21e05 ***
#t 4.111e05 2.439e06 16.86 7.26e05 ***
#
#Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
#Residual standard error: 0.0005101 on 4 degrees of freedom
#Multiple Rsquared: 0.9861, Adjusted Rsquared: 0.9826
#Fstatistic: 284.2 on 1 and 4 DF, pvalue: 7.259e05
So we got a higher \(R^2\) on the second order model. The reaction rate can be considered second order. What is the reaction rate constant, \(k_A\) for this system?
Source code: Using MATLAB or Octave
t = [0, 50, 100, 150, 200, 250]; % [minutes]
CA = [154, 114, 87, 76, 70, 58]; % [mol/m^3]
% Plot the data first. See the expected trend. It it decreasing nonlinearly, so
% it is either first or second order (but not zeroth order)
figure
plot(t, CA, 'o')
grid on
% Some template code for the linear regression
x = t;
y = log(CA(1)./CA);
n = numel(y);
% Assume it is a first order, rA = k CA; so plot log(CA0/CA) against t
figure
plot(x, y, 'o')
grid on
% Does not quite look like a straighTSt line, but let us fit a leastsquares model anyway
% Fit the model y = b x + 0 (i.e. force the intercept to zero)
X = [x(:)];
y = y(:); % make sure it is a column vector
b = inv(X'*X)*X'*y; % recall this from the 3E4 course
%b = regress(y, X); % only if you have the Statistics Toolbox in MATLAB
% Plot the data along with the fitted line:
figure
plot(x, y, 'o')
hold('on')
grid('on')
plot(x, X*b, 'r')
xlabel('x values')
ylabel('y values')
legend({'Original data', 'Fitted line'}, 'Location', 'Best')
% Additional calculations
predicted = X*b;
resids = y  predicted; % resids = e = y  Xb
RSS = resids' * resids; % residual sum of squares
TSS = sum((y  mean(y)).^2); % total sum of squares
R2_first_order = 1  RSS/TSS
% Now try a second order model: rA = k CA^2; so plot 1/CA against t
figure
plot(t, 1./CA, 'o')
grid('on')
% Definitely more linear. Let us fit the least squares model,
% 1/CA = 1/CA0 + kt, or y = b0 + b1 x, where y = 1/CA and x = t, and there is an intercept
% Some template code for the linear regression
x = t;
y = 1./CA;
n = numel(y);
X = [ones(n,1) x(:)];
y = y(:); % make sure it is a column vector
b = inv(X'*X)*X'*y; % recall this from the 3E4 course
% b = regress(y, X); % only if you have the Statistics Toolbox in MATLAB
% Plot the data along with the fitted line:
figure
plot(x, y, 'o')
hold('on')
grid('on')
plot(x, X*b, 'r')
xlabel('x values')
ylabel('y values')
legend({'Original data', 'Fitted line'}, 'Location', 'Best')
% Additional calculations
predicted = X*b;
resids = y  predicted; % resids = e = y  Xb
RSS = resids' * resids; % residual sum of squares
TSS = sum((y  mean(y)).^2); % total sum of squares
R2_second_order = 1  RSS/TSS