Está en la página 1de 123

Cutlip and Shacham: Problem Solving in Chemical and Biochemical Engineering

Chapter 3
Regression and Correlation of Data
Cheng-Liang Chen
PSE
LABORATORY
Department of Chemical Engineering
National TAIWAN University
Chen CL 1
Estimation of Antoine Equation Parameters
Using Nonlinear Regression
Concepts Utilized: Direct use of the Antoine equation to correlate vapor
pressure versus temperature data.
Numerical Methods: Nonlinear regression of a general algebraic expression with
determination of the overall variance and condence intervals of individual
parameters.
Problem Statement:
The Antoine equation is a widely used vapor pressure correlation that utilizes three
parameters, A, B, and C. It is often expressed by
P
v
= 10
A+
B
T+C
(3-1)
where P
v
is the vapor pressure in mm Hg and T is the temperature in
o
C.
Vapor pressure data for propane (P
a
) versus temperature (K) is found in Table
B-5 in Appendix B. Convert this data set to vapor pressure in mm Hg and
temperature in
o
C. Then
Chen CL 2
(a) Determine the parameters of the Antoine equation and the corresponding 95%
condence intervals for the parameters from the given data set by using nonlinear
regression on Equation (3-1).
(b) Calculate the overall variance for the Antoine equation.
(c) Prepare a residual plot for the Antoine equation.
(d) Assess the precision of the data and the appropriateness of the Antoine equation
for correlation of the data set.
Solution:
The form of the Antoine equation to be considered in this problem is to be
regressed in its nonlinear form. An alternative treatment is to use multiple linear
regression on the logarithmic form of this equation, but this transformation is not
fully suitable, as discussed in Problem 2.8.
General nonlinear regression can be used to determine the parameters of an
explicit algebraic equation, or model equation, as dened by Equation (3-2):
y = f(x
1
, . . . , x
n
; a
1
, . . . , a
m
) (3-2)
Chen CL 3
where the single dependent variable is y, the n independent variables are
x
1
, . . . , x
n
, and the m parameters are a
l
, . . . a
m
. It is usually assumed that the
experimental errors in the preceding equation are normally distributed with
constant variance. Nonlinear regression algorithms determine the parameters for a
particular model by minimizing the least-squares objective function (L8) given by
LS =
N

i=1

y
i(obs)
y
i(calc)

where N is the number of data points and (obs) and (calc) refer to observed and
calculated values of the dependent variable.
The overall estimate of the model variance,
2
, is calculated from

2
=
N

i=1

y
i(obs)
y
i(calc)

=
LS

where is the degrees of freedom, which is equal to the number of data points
less the number of model parameters, (N m). Thus an algorithm that
minimizes the least-squares objective function also minimizes the variance.
Often the variance is used to compare the goodness of t for various models.
Chen CL 4
A widely used graphical presentation that indicates any systematic diculties with
a particular model is called the residuals plot. This is simply the error,
i
, in the
model plotted versus the observed value of the independent variable, y
i(obs)
with
the error given by

i
= y
i(obs)
y
i(calc)
Nonlinear Regression of the Antoine Equation The rst step is to enter the
data by assigning a name to each variable (column). The column for the vapor
pressure in P
a
will be designated as P and the column for the temperature in K
will be denoted as TK. Since the Antoine equation is to correlate the vapor
pressure in mm Hg and the temperature in
o
C, then a new column denoted as Pv
and another new column denoted as TC can be created that calculate the pressure
and temperature in units of mm Hg and
o
C by
Pv = .0075002 P
TC = TK 273.15
Chen CL 5
function P3_01_CCL
clear, clc, format short g, format compact
xyData=[-187.68 1.268E-06
-183.15 7.268E-06
-173.15 0.0001883
-163.15 0.0025884
-153.15 0.0221106
-143.15 0.1315085
-133.15 0.5900482
-123.15 2.117681
-113.15 6.352669
-103.15 16.50044
-93.15 37.87601
-83.15 78.7521
-73.15 150.754
-63.15 269.2572
-53.15 453.7621
-42.08 757.5202
-33.15 1110.03
-23.15 1635.044
-13.15 2332.562
-3.15 3225.086
Chen CL 6
6.85 4365.116
16.85 5767.654
26.85 7485.2
36.85 9525.254
46.85 1.2E+04
56.85 1.485E+04
66.85 1.823E+04
76.85 2.213E+04
86.85 2.663E+04];
X=xyData(:,1);
m=size(X,1); %Determine the number of data points
Y=xyData(:,2);
prob_title = ([\bf Antoine Eq. Par.s, Nonlinear Reg.]);
dep_var_name= [\bf Vapor P (mmHg) ];
ind_var_name= [\bf Temperature (C)];
parm=[6 -1000 200]; % Initial guess for A, B, C
npar=size(parm,2); % Determine the number of the parameters
options = optimset(MaxFunEvals,1000); % Change the default value for MaxFunEvals
Beta = fminsearch(@AntFun,parm,options,X,Y); % Find optimal parameters using fminsearch
[f,Ycalc]= AntFun(Beta,X,Y); % Compute Y (calculated) at the optimum
disp( Results, Antoine Eq. Par.s, Nonlinear Regression );
Res=[];
Chen CL 7
for i=1:npar
Res=[Res; i Beta(i)];
end
disp( Parameter No. Value );
disp(Res);
s2=sum((Y-Ycalc)*(Y-Ycalc))/(m-npar); %variance
disp([ Variance , num2str(s2)]);
ymean=mean(Y);
R2=(Ycalc-ymean)*(Ycalc-ymean)/((Y-ymean)*(Y-ymean));%linear correlation coefficient
disp([ Correlation Coefficient , num2str(R2)])
subplot(2,1,1)
plot(X,Ycalc,r-,X,Y,b+,LineWidth,2) %Plot of experimental and calculated data
set(gca,FontSize,14,Linewidth,2)
title([\bf Cal./Exp. Data prob_title],fontSize,12)
xlabel([ind_var_name],fontSize,14)
ylabel([dep_var_name],fontSize,14)
subplot(2,1,2)
plot(Y,Y-Ycalc,*,LineWidth,2) % Residual plot
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual Plot, prob_title ],fontSize,12)
xlabel([dep_var_name \bf (Measured)],fontSize,14)
ylabel(\bf Residual,fontSize,14)
Chen CL 8
function [f,Ycalc]=AntFun(parm,X,Y)
a=parm(1);
b=parm(2);
c=parm(3);
for i=1:size(X,1);
Ycalc(i,1)=10^(a+b/(X(i)+c));
end
resid(:,1)=Y-Ycalc;
f=resid*resid;
Results, Antoine Eq. Par.s, Nonlinear Regression
Parameter No. Value
1 7.2644
2 -1046.3
3 281.61
Variance 507.9109
Correlation Coefficient 0.99922
Chen CL 9
Correlation of Thermodynamic and
Physical Properties of n-Propane
Concepts Utilized: Correlations for heat capacity, thermal conductivity,
viscosity, and latent heat of vaporization.
Numerical Methods: Linear and nonlinear regression of data with linearization
and transformation functions.
Problem Statement:
Tables B-7 through B-10 present values for dierent properties of propane
(heat capacity, thermal conductivity for gas, viscosity, and latent heat of
vaporization for liquid) as a function of temperature.
Determine appropriate correlations for the properties of propane listed in Tables
B-7 through B-10 using suggested expressions; given in the chemical
engineering literature.
Solution:
Heat Capacity for a Gas Heat capacity for propane gas is given in Table
B-7 for temperatures between 50 K and 1500 K. According to Perry et al., the
Chen CL 10
heat capacities of gases are most commonly represented as a simple polynomial:
C
p
= a
0
+ a
1
T + a
2
T
2
+ a
3
T
3
+ . . .
Thermal Conductivity Thermal conductivity for gaseous propane is given in
Table B-8 for the temperature range 231 K to 600 K. Perry et al. note that over
small temperature ranges the thermal conductivity of low-pressure gases can be
fairly well correlated by a linear equation, which is also a rst degree polynomial.
However, we can try polynomials here. For a wide range of temperature, Perry et
al. recommend the correlation of thermal conductivity, k, with T
n
, where T is the
absolute temperature and n 1.8. This correlation can be directly evaluated with
nonlinear regression using the form below, where both c and n are parameters.
k = cT
n
Liquid Viscosity The recommended correlation for viscosity of liquids by Perry
et al. is similar to the Antoine equation for vapor pressure:
log() = A + B/(T + C)
Chen CL 11
where is the viscosity and A, B and C are parameters. If T is expressed in
Kelvin, parameter C can be approximated by C = 17.71 0.19T
b
, where T
b
is the
normal boiling point in Kelvin. For n-propane the normal boiling point is 231 K;
thus the approximate value of C is 26.18.
A four-parameter equation used in Reid et a1. provides another possible
correlation equation for viscosity of liquids:
log() = A + B/T
C
log(T) + DT
2
Heat of Vaporization Heat of vaporization data for propane are shown in
Table B-10 for the temperature range of 85.47 K to 360 K. Heat of vaporization
can be correlated by an equation based on the Watson relation (Perry et al.):
H = A(T
C
T)
n
Watsons recommended value for n is 0.38, but n can be found by regression of
the experimental data. The critical temperature of propane is 369.83 K. The
equation can be directly used in nonlinear regression, or it can be linearized by
taking the log of each side yielding
log(H) = log(A) + nlog(T
C
T)
Chen CL 12
function P3_03A_CCL
clear, clc,format short g, format compact
prob_title = ([ Heat Cap. of Gaseous Propane]);
ind_var_name= [\bf Temperature (K)];
dep_var_name= [\bf Cp (kJ/kg-mol-K) ];
xyData=[ 50 34.06
100 41.3
150 48.79
200 56.07
273.16 68.74
298.15 73.6
300 73.93
400 94.01
500 112.59
600 128.7
700 142.67
800 154.77
900 163.35
1000 174.6
1100 182.67
1200 189.74
1300 195.85
Chen CL 13
1400 201.21
1500 205.89];
x =xyData(:,1);
y =xyData(:,2);
[m,n]=size(x);
freeparm=input( Input 1 if there is a free parameter, 0 otherwise );
degree =input( Enter the degree of the polynomial );
[Beta, ycal,ConfInt, Var, R2, n]=PolyReg(x,y,degree,freeparm);
disp( Results, Heat Capacity of Gaseous Propane );
Res=[];
for i=0:n-1
if freeparm==0; ii=i+1; else ii=i; end
Res=[Res; ii Beta(i+1) ConfInt(i+1)];
end
disp( Parameter No. Beta Conf_int);
disp(Res);
disp([ Variance , num2str(Var)]);
disp([ Correlation Coefficient , num2str(R2)]);
subplot(2,1,1)
plot(x,ycal, r-,x,y,bo,LineWidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Cal/exp data prob_title],FontSize,12)
Chen CL 14
xlabel([\bf Temperature (K)],FontSize,14)
ylabel([dep_var_name],FontSize,14)
subplot(2,1,2)
plot(y,y-ycal,*,LineWidth,2) % residual plot
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual plot, prob_title],FontSize,12)
xlabel([dep_var_name \bf (measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Beta, ycal,ConfInt, Var, R2, n]=PolyReg(x,y,degree,freeparm)
tdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...
2.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199...
2.1098 2.1009 2.093 2.086 2.0796 2.0739 2.0687 2.0639...
2.0595 2.0555 2.0518 2.0484 2.0452 2.0423 2.0395 2.0369...
2.0345 2.0322 2.0301 2.0281 2.0262 2.0244 2.0227 2.0211...
2.0195 2.0181 2.0167 2.0154 2.0141]; % 95 percent probability t-distr. values
if freeparm==1
n=degree+1;
else
n=degree;
end
m=size(x,1);
Chen CL 15
for i=1:m
for j=1:n
if freeparm==1
p=j-1;
else
p=j;
end
X(i,j)=x(i)^p; %Calculate powers of the independent variable and put them in the matrix X
end
end
Beta=X\y; % Solve XBeta = Y using QR decomposition
ycal=X*Beta; % Calculated dependent variable values
Var=sum((y-ycal)*(y-ycal))/(m-n); % variance
if (m-n)>45
t=2.07824-0.0017893*(m-n)+0.000008089*(m-n)^2;
else
t=tdistr95(m-n);
end
A=X*X;
Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrix
for i=1:n
ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals
Chen CL 16
end
ymean=mean(y);
R2=(ycal-ymean)*(ycal-ymean)/((y-ymean)*(y-ymean));%linear correlation coefficient
Input 1 if there is a free parameter, 0 otherwise 1
Enter the degree of the polynomial 3
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 4.135355e-020.
> In P3_03A_CCL>PolyReg at 92
In P3_03A_CCL at 30
Results, Heat Capacity of Gaseous Propane
Parameter No. Beta Conf_int
0 20.524 4.6386
1 0.19647 0.027803
2 -2.6848e-005 4.2358e-005
3 -1.5129e-008 1.8159e-008
Variance 6.0069
Correlation Coefficient 0.99862
Chen CL 17
Chen CL 18
function P3_03B1_CCL
clear, clc,format short g, format compact
prob_title = ([ Thermal Conductivity of Gaseous Propane ]);
ind_var_name=[\bf Temp. (K)];
dep_var_name=[\bf Thermal Conductivity (W/m*K) ];
xyData=[ 231.07 1.14E-02
240 1.21E-02
260 1.39E-02
280 1.59E-02
300 1.80E-02
320 2.02E-02
340 2.26E-02
360 2.52E-02
380 2.78E-02
400 3.06E-02
420 3.34E-02
440 3.63E-02
460 3.93E-02
480 4.24E-02
500 4.55E-02
520 4.87E-02
540 5.20E-02
Chen CL 19
560 5.53E-02
580 5.86E-02
600 6.19E-02];
x=xyData(:,1);
y=xyData(:,2);
[m,n]=size(x);
freeparm=input( Input 1 if there is a free parameter, 0 otherwise );
degree=input( Enter the degree of the polynomial );
[Beta, ycal,ConfInt, Var, R2, n]=PolyReg(x,y,degree,freeparm);
disp([ Results, prob_title]);
Res=[];
for i=0:n-1
if freeparm==0; ii=i+1; else ii=i; end
Res=[Res; ii Beta(i+1) ConfInt(i+1)];
end
disp( Parameter No. Beta Conf_int);
disp(Res);
disp([ Variance , num2str(Var)]);
disp([ Correlation Coefficient , num2str(R2)]);
subplot(2,1,1)
plot(x,ycal,r-,x,y,bo,Linewidth,2) %Plot of experimental and calculated data
set(gca,FontSize,14,Linewidth,2)
Chen CL 20
title([\bf Cal/Exp Data prob_title],FontSize,12)
xlabel([ind_var_name],FontSize,14)
ylabel([dep_var_name],FontSize,14)
subplot(2,1,2)
plot(y,y-ycal,*,Linewidth,2) % Residual plot
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title ],FontSize,12)
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Beta, ycal,ConfInt, Var, R2, n]=PolyReg(x,y,degree,freeparm)
tdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...
2.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199...
2.1098 2.1009 2.093 2.086 2.0796 2.0739 2.0687 2.0639...
2.0595 2.0555 2.0518 2.0484 2.0452 2.0423 2.0395 2.0369...
2.0345 2.0322 2.0301 2.0281 2.0262 2.0244 2.0227 2.0211...
2.0195 2.0181 2.0167 2.0154 2.0141]; % 95 percent probability t-distr. values
if freeparm==1
n=degree+1;
else
n=degree;
end
Chen CL 21
m=size(x,1);
for i=1:m
for j=1:n
if freeparm==1
p=j-1;
else
p=j;
end
X(i,j)=x(i)^p; %Calculate powers of the independent variable and put them in the matrix X
end
end
Beta=X\y; % Solve XBeta = Y using QR decomposition
ycal=X*Beta; % Calculated dependent variable values
Var=sum((y-ycal)*(y-ycal))/(m-n); % variance
if (m-n)>45
t=2.07824-0.0017893*(m-n)+0.000008089*(m-n)^2;
else
t=tdistr95(m-n);
end
A=X*X;
Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrix
for i=1:n
Chen CL 22
ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals
end
ymean=mean(y);
R2=(ycal-ymean)*(ycal-ymean)/((y-ymean)*(y-ymean));%linear correlation coefficient
Input 1 if there is a free parameter, 0 otherwise 1
Enter the degree of the polynomial 3
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 2.731195e-020.
> In P3_03B1_CCL>PolyReg at 86
In P3_03B1_CCL at 31
Results, Thermal Conductivity of Gaseous Propane
Parameter No. Beta Conf_int
0 0.0062337 0.00091915
1 -4.7525e-005 7.2333e-006
2 3.4436e-007 1.8141e-008
3 -1.8414e-010 1.4585e-011
Variance 1.1612e-009
Correlation Coefficient 1
Chen CL 23
Chen CL 24
function P3_03B2_CCL
clear, clc, format short g, format compact
xyData=[231.07 1.14E-02
240 1.21E-02
260 1.39E-02
280 1.59E-02
300 1.80E-02
320 2.02E-02
340 2.26E-02
360 2.52E-02
380 2.78E-02
400 3.06E-02
420 3.34E-02
440 3.63E-02
460 3.93E-02
480 4.24E-02
500 4.55E-02
520 4.87E-02
540 5.20E-02
560 5.53E-02
580 5.86E-02
600 6.19E-02];
Chen CL 25
X=xyData(:,1);
m=size(X,1); %Determine the number of data points
Y=xyData(:,2);
prob_title = ([ Thermal Conductivity of Gaseous Propane]);
dep_var_name=[\bf Thermal Conductivity (W/m*K) ];
ind_var_name=[\bf Temperature (K)];
parm=[0.001 1.8];
npar=size(parm,2); % Determine the number of the parameters
options=optimset(MaxFunEvals,1000); % Change the default value for MaxFunEvals
Beta=fminsearch(@NonlinFun,parm,options,X,Y); % Find optimal parameters using fminsearch
[f,Ycalc] = NonlinFun(Beta,X,Y); % Compute Y (calculated) at the optimum
disp([ Results, prob_title ]);
Res=[];
for i=1:npar
Res=[Res; i Beta(i)];
end
disp( Parameter No. Value );
disp(Res);
s2=sum((Y-Ycalc)*(Y-Ycalc))/(m-npar); %variance
disp([ Variance , num2str(s2)]);
ymean=mean(Y);
R2=(Ycalc-ymean)*(Ycalc-ymean)/((Y-ymean)*(Y-ymean));%linear correlation coefficient
Chen CL 26
disp([ Correlation Coefficient , num2str(R2)])
subplot(2,1,1)
plot(X,Ycalc,r-,X,Y,bo,Linewidth,2) %Plot of experimental and calculated data
set(gca,FontSize,14,Linewidth,2)
title([\bf Cal/Exp Data prob_title],FontSize,12)
xlabel([ind_var_name],FontSize,14)
ylabel([dep_var_name],FontSize,14)
subplot(2,1,2)
plot(Y,Y-Ycalc,*,Linewidth,2) % Residual plot
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title ],FontSize,12)
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [f,Ycalc]=NonlinFun(parm,X,Y)
c=parm(1);
n=parm(2);
for i=1:size(X,1);
Ycalc(i,1)=c*X(i)^n;
end
resid(:,1)=Y-Ycalc;
f=resid*resid;
Chen CL 27
Results, Thermal Conductivity of Gaseous Propane
Parameter No. Value
1 7.2698e-007
2 1.7762
Variance 7.1848e-008
Correlation Coefficient 0.9943
Chen CL 28
Chen CL 29
function P3_03C1_CCL
clear, clc, format short g, format compact
prob_title = ([ Propane viscosity with Antoine Eq]);
ind_var_name=[\bf 1/(T+C) ];
dep_var_name=[\bf log (Viscosity) ];
xyData=[-2.417937 0.0135465
-2.640165 0.0119303
-2.815309 0.0106587
-2.966576 0.0096321
-3.079877 0.0087858
-3.181115 0.0080762
-3.262807 0.0074727
-3.343902 0.0069531
-3.417937 0.0065011
-3.473661 0.0061043
-3.542118 0.0057531
-3.649752 0.0051594
-3.744727 0.0046768
-3.841638 0.0042768
-3.886057 0.0041014
-3.931814 0.0039398
-3.978811 0.0037905
Chen CL 30
-4.018181 0.003652];
X=xyData(:,2:end);
y=xyData(:,1);
[m,n]=size(X);
freeparm=input( Input 1 if there is a free parameter, 0 otherwise > );
[Beta, ConfInt,ycal, Var, R2]=MlinReg(X,y,freeparm);
disp([ Results, prob_title]);
Res=[];
if freeparm==0, nparm = n-1; else nparm = n; end
for i=0:nparm
if freeparm, ii=i+1; else ii=i; end
Res=[Res; ii Beta(i+1) ConfInt(i+1)];
end
disp( Parameter No. Beta Conf_int);
disp(Res);
disp([ Variance , num2str(Var)]);
disp([ Correlation Coefficient , num2str(R2)]);
subplot(2,1,1)
plot(X(:,1),ycal, r-,X(:,1),y,bo,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Cal/Exp Data prob_title],FontSize,12)
xlabel([ind_var_name],FontSize,14)
Chen CL 31
ylabel([dep_var_name],FontSize,14)
subplot(2,1,2)
plot(y,y-ycal,*,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title],FontSize,12) % residual plot
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Beta, ConfInt, ycalc, Var, R2]=MlinReg(X,y,freeparm)
[m,n]=size(X); % m-number of rows, n-number of columns
if freeparm
X=[ones(m,1) X]; % Add column of ones if there is a free parameter
npar=n+1;
else
npar=n;
end
Beta=X\y; % Solve XBeta = Y using QR decomposition
ycalc=X*Beta; % Calculated dependent variable values
Var=((y-ycalc)*(y-ycalc))/(m-npar); % variance
ymean=mean(y);
R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correlation coefficient
% Calculate the confidence intervals
Chen CL 32
A=X*X;
Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrix
tdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...
2.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199...
2.1098 2.1009 2.093 2.086 2.0796 2.0739 2.0687 2.0639...
2.0595 2.0555 2.0518 2.0484 2.0452 2.0423 2.0395 2.0369...
2.0345 2.0322 2.0301 2.0281 2.0262 2.0244 2.0227 2.0211...
2.0195 2.0181 2.0167 2.0154 2.0141]; % 95 percent probability t-distr. values
if (m-npar)>45
t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degrees of freedom > 45
else
t=tdistr95(m-npar);
end
for i=1:npar
ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals
end
Input 1 if there is a free parameter, 0 otherwise > 1
Results, Propane viscosity with Antoine Eq
Parameter No. Beta Conf_int
1 -4.5104 0.067488
2 159.94 8.9729
Chen CL 33
Variance 0.0026888
Correlation Coefficient 0.98892
Chen CL 34
function P3_03C2_CCL
clear, clc, format short g, format compact
xyData=[100 3.82E-03
110 2.29E-03
120 1.53E-03
130 1.08E-03
140 8.32E-04
150 6.59E-04
160 5.46E-04
170 4.53E-04
180 3.82E-04
190 3.36E-04
200 2.87E-04
220 2.24E-04
240 1.80E-04
260 1.44E-04
270 1.30E-04
280 1.17E-04
290 1.05E-04
300 9.59E-05];
X=xyData(:,1);
m=size(X,1); %Determine the number of data points
Chen CL 35
Y=log10(xyData(:,2));
prob_title = ([ Visc. Propane, Antoine Eq. Params, Nln. Regr]);
dep_var_name=[\bf log (viscosity) ];
ind_var_name=[\bf Temperature (K)];
parm=[-4.51 159.9 -26.18];
npar=size(parm,2); % Determine the number of the parameters
options=optimset(MaxFunEvals,1000); % Change the default value for MaxFunEvals
Beta=fminsearch(@AntFun,parm,options,X,Y); % Find optimal parameters using fminsearch
[f,Ycalc]=AntFun(Beta,X,Y); % Compute Y (calculated) at the optimum
disp([ Results, prob_title ]);
Res=[];
for i=1:npar
Res=[Res; i Beta(i)];
end
disp( Parameter No. Value );
disp(Res);
s2=sum((Y-Ycalc)*(Y-Ycalc))/(m-npar); %variance
disp([ Variance , num2str(s2)]);
ymean=mean(Y);
R2=(Ycalc-ymean)*(Ycalc-ymean)/((Y-ymean)*(Y-ymean));%linear correlation coefficient
disp([ Correlation Coefficient , num2str(R2)])
subplot(2,1,1)
Chen CL 36
plot(X,Ycalc,r-,X,Y,bo,Linewidth,2) %Plot of experimental and calculated data
set(gca,FontSize,14,Linewidth,2)
title([\bf Cal/Exp Data prob_title],FontSize,12)
xlabel([ind_var_name],FontSize,14)
ylabel([dep_var_name],FontSize,14)
subplot(2,1,2)
plot(Y,Y-Ycalc,*,Linewidth,2) % Residual plot
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title ],Linewidth,2)
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [f,Ycalc]=AntFun(parm,X,Y)
a=parm(1);
b=parm(2);
c=parm(3);
for i=1:size(X,1);
Ycalc(i,1)=(a+b/(X(i)+c));
end
resid(:,1)=Y-Ycalc;
f=resid*resid;
Chen CL 37
Results, Visc. Propane, Antoine Eq. Params, Nln. Regr
Parameter No. Value
1 -4.9379
2 308.26
3 23.967
Variance 0.00047507
Correlation Coefficient 0.99816
Chen CL 38
Chen CL 39
function P3_03D1_CCL
clear, clc, format short g, format compact
prob_title = ([ Propane Heat of Vap., Linear Regr.]);
ind_var_name=[\bf log(TC-T)];
dep_var_name=[\bf log(deltaH) ];
xyData=[7.394452 2.453869
7.390935 2.446894
7.383815 2.43109
7.374748 2.414689
7.367356 2.397645
7.359835 2.379904
7.352183 2.361407
7.344392 2.342087
7.33646 2.321868
7.32838 2.300661
7.320146 2.278365
7.311754 2.254862
7.303196 2.230014
7.294466 2.203658
7.285557 2.175599
7.274158 2.142264
7.262451 2.113375
Chen CL 40
7.25042 2.078566
7.238046 2.040721
7.222716 1.999261
7.206826 1.953421
7.187521 1.902166
7.164353 1.844042
7.139879 1.776919
7.10721 1.697491
7.071882 1.60021
7.021189 1.474653
6.951823 1.297323
6.833147 0.9925535];
X=xyData(:,2:end);
y=xyData(:,1);
[m,n]=size(X);
freeparm=input( Input 1 if there is a free parameter, 0 otherwise > );
[Beta, ConfInt,ycal, Var, R2]=MlinReg(X,y,freeparm);
disp([ Results, prob_title]);
Res=[];
if freeparm==0, nparm = n-1; else nparm = n; end
for i=0:nparm
if freeparm, ii=i+1; else ii=i; end
Chen CL 41
Res=[Res; ii Beta(i+1) ConfInt(i+1)];
end
disp( Parameter No. Beta Conf_int);
disp(Res);
disp([ Variance , num2str(Var)]);
disp([ Correlation Coefficient , num2str(R2)]);
subplot(2,1,1)
plot(X(:,1),ycal, r-,X(:,1),y,bo,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Cal/Exp Data prob_title],FontSize,12)
xlabel([ind_var_name],FontSize,14)
ylabel([dep_var_name],FontSize,14)
subplot(2,1,2)
plot(y,y-ycal,*,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title],FontSize,14) % residual plot
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Beta, ConfInt, ycalc, Var, R2]=MlinReg(X,y,freeparm)
[m,n]=size(X); % m-number of rows, n-number of columns
if freeparm
Chen CL 42
X=[ones(m,1) X]; % Add column of ones if there is a free parameter
npar=n+1;
else
npar=n;
end
Beta=X\y; % Solve XBeta = Y using QR decomposition
ycalc=X*Beta; % Calculated dependent variable values
Var=((y-ycalc)*(y-ycalc))/(m-npar); % variance
ymean=mean(y);
R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correlation coefficient
% Calculate the confidence intervals
A=X*X;
Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrix
tdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...
2.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199...
2.1098 2.1009 2.093 2.086 2.0796 2.0739 2.0687 2.0639...
2.0595 2.0555 2.0518 2.0484 2.0452 2.0423 2.0395 2.0369...
2.0345 2.0322 2.0301 2.0281 2.0262 2.0244 2.0227 2.0211...
2.0195 2.0181 2.0167 2.0154 2.0141]; % 95 percent probability t-distr. values
if (m-npar)>45
t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degrees of freedom > 45
else
Chen CL 43
t=tdistr95(m-npar);
end
for i=1:npar
ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals
end
Input 1 if there is a free parameter, 0 otherwise > 1
Results, Propane Heat of Vap., Linear Regr.
Parameter No. Beta Conf_int
1 6.4664 0.0076187
2 0.3765 0.0036327
Variance 1.1952e-005
Correlation Coefficient 0.9994
Chen CL 44
Chen CL 45
function P3_03D2_CCL
clear, clc, format short g, format compact
xyData=[85.47 2.48E+07
90 2.46E+07
100 2.42E+07
110 2.37E+07
120 2.33E+07
130 2.29E+07
140 2.25E+07
150 2.21E+07
160 2.17E+07
170 2.13E+07
180 2.09E+07
190 2.05E+07
200 2.01E+07
210 1.97E+07
220 1.93E+07
231.07 1.88E+07
240 1.83E+07
250 1.78E+07
260 1.73E+07
270 1.67E+07
Chen CL 46
280 1.61E+07
290 1.54E+07
300 1.46E+07
310 1.38E+07
320 1.28E+07
330 1.18E+07
340 1.05E+07
350 8.95E+06
360 6.81E+06];
X=xyData(:,1);
m=size(X,1); %Determine the number of data points
Y=xyData(:,2);
prob_title = ([ Heat of Vaporization of Propane, NlN Reg.]);
dep_var_name= [\bf Heat of Vaporization (J/kmol) ];
ind_var_name= [\bf Temperature (K)];
parm=[2.926e6 0.3765];
npar=size(parm,2); % Determine the number of the parameters
options=optimset(MaxFunEvals,1000); % Change the default value for MaxFunEvals
Beta=fminsearch(@NonlinFun,parm,options,X,Y); % Find optimal parameters using fminsearch
[f,Ycalc]=NonlinFun(Beta,X,Y); % Compute Y (calculated) at the optimum
disp([ Results, prob_title ]);
Res=[];
Chen CL 47
for i=1:npar
Res=[Res; i Beta(i)];
end
disp( Parameter No. Value );
disp(Res);
s2=sum((Y-Ycalc)*(Y-Ycalc))/(m-npar); %variance
disp([ Variance , num2str(s2)]);
ymean=mean(Y);
R2=(Ycalc-ymean)*(Ycalc-ymean)/((Y-ymean)*(Y-ymean));%linear correlation coefficient
disp([ Correlation Coefficient , num2str(R2)])
subplot(2,1,1)
plot(X,Ycalc,r-,X,Y,bo,Linewidth,2) %Plot of experimental and calculated data
set(gca,FontSize,14,Linewidth,2)
title([\bf Cal/Exp Data prob_title],FontSize,12)
xlabel([ind_var_name],FontSize,14)
ylabel([dep_var_name],FontSize,14)
subplot(2,1,2)
plot(Y,Y-Ycalc,*,Linewidth,2) % Residual plot
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title ],FontSize,12)
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
Chen CL 48
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [f,Ycalc]=NonlinFun(parm,X,Y)
A=parm(1);
n=parm(2);
for i=1:size(X,1);
Ycalc(i,1)=A*(369.83-X(i))^n;
end
resid(:,1)=Y-Ycalc;
f=resid*resid;
Results, Heat of Vaporization of Propane, NlN Reg.
Parameter No. Value
1 2.9686e+006
2 0.37362
Variance 19016122798.9036
Correlation Coefficient 0.99712
Chen CL 49
Chen CL 50
function P3_03D3_CCL
clear, clc,format short g, format compact
prob_title = ([ Heat of Vaporization of Propane, Polynomial ]);
ind_var_name=[\bf Temperature (K)];
dep_var_name=[\bf Heat of Vaporization (J/Kmol) ];
xyData=[ 85.47 2.48E+07
90 2.46E+07
100 2.42E+07
110 2.37E+07
120 2.33E+07
130 2.29E+07
140 2.25E+07
150 2.21E+07
160 2.17E+07
170 2.13E+07
180 2.09E+07
190 2.05E+07
200 2.01E+07
210 1.97E+07
220 1.93E+07
231.07 1.88E+07
240 1.83E+07
Chen CL 51
250 1.78E+07
260 1.73E+07
270 1.67E+07
280 1.61E+07
290 1.54E+07
300 1.46E+07
310 1.38E+07
320 1.28E+07
330 1.18E+07
340 1.05E+07
350 8.95E+06
360 6.81E+06];
x=xyData(:,1);
y=xyData(:,2);
[m,n]=size(x);
freeparm=input( Input 1 if there is a free parameter, 0 otherwise );
degree= input( Enter the degree of the polynomial );
[Beta, ycal,ConfInt, Var, R2, n]=PolyReg(x,y,degree,freeparm);
disp([ Results, prob_title]);
Res=[];
for i=0:n-1
if freeparm==0; ii=i+1; else ii=i; end
Chen CL 52
Res=[Res; ii Beta(i+1) ConfInt(i+1)];
end
disp( Parameter No. Beta Conf_int);
disp(Res);
disp([ Variance , num2str(Var)]);
disp([ Correlation Coefficient , num2str(R2)]);
%Plot of experimental and calculated data
%
% for i=1:m
% index(i)=i;
% end
subplot(2,1,1)
plot(x,ycal, r-,x,y,bo,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Cal/exp data prob_title],FontSize,12)
xlabel([\bf Temperature (K)],FontSize,14)
ylabel([dep_var_name],FontSize,14)
subplot(2,1,2)
plot(y,y-ycal,*,Linewidth,2) % residual plot
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title],FontSize,12)
xlabel([dep_var_name \bf (measured)],FontSize,14)
Chen CL 53
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Beta, ycal,ConfInt, Var, R2, n]=PolyReg(x,y,degree,freeparm)
tdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...
2.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199...
2.1098 2.1009 2.093 2.086 2.0796 2.0739 2.0687 2.0639...
2.0595 2.0555 2.0518 2.0484 2.0452 2.0423 2.0395 2.0369...
2.0345 2.0322 2.0301 2.0281 2.0262 2.0244 2.0227 2.0211...
2.0195 2.0181 2.0167 2.0154 2.0141]; % 95 percent probability t-distr. values
if freeparm==1
n=degree+1;
else
n=degree;
end
m=size(x,1);
for i=1:m
for j=1:n
if freeparm==1
p=j-1;
else
p=j;
end
Chen CL 54
X(i,j)=x(i)^p; %Calculate powers of the independent variable and put them in the matrix X
end
end
Beta=X\y; % Solve XBeta = Y using QR decomposition
ycal=X*Beta; % Calculated dependent variable values
Var=sum((y-ycal)*(y-ycal))/(m-n); % variance
if (m-n)>45
t=2.07824-0.0017893*(m-n)+0.000008089*(m-n)^2;
else
t=tdistr95(m-n);
end
A=X*X;
Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrix
for i=1:n
ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals
end
ymean=mean(y);
R2=(ycal-ymean)*(ycal-ymean)/((y-ymean)*(y-ymean));%linear correlation coefficient
Input 1 if there is a free parameter, 0 otherwise 1
Enter the degree of the polynomial 3
Warning: Matrix is close to singular or badly scaled.
Chen CL 55
Results may be inaccurate. RCOND = 5.894599e-018.
> In P3_03D3_CCL>PolyReg at 100
In P3_03D3_CCL at 40
Results, Heat of Vaporization of Propane, Polynomial
Parameter No. Beta Conf_int
0 3.3335e+007 1.5284e+006
1 -1.4048e+005 24249
2 602.57 117.08
3 -1.1448 0.17534
Variance 40745270933.3095
Correlation Coefficient 0.99847
Chen CL 56
Chen CL 57
Heat Transfer Correlations
from Dimensional Analysis
Concepts Utilized: Correlation of heat transfer data using dimensionless groups.
Numerical Methods: Linear and nonlinear regression of data with linearization
and use of transformation functions.
Problem Statement:
An important tool in the correlation of engineering data is the use of dimensional
analysis. This treatment leads to the determination of the independent
dimensionless numbers, which may be important for a particular problem. Linear
and nonlinear regression can be very useful in determining the correlations of
dimensionless numbers with experimental data.
A treatment of heat transfer within a pipe has been considered by Geankoplis
using the Buckingham method, and the result is that the Nusselt number is
expected to be a function of the Reynolds and Prandtl numbers.
Nu = f(Re, Pr) or
hD
k
= f

Dv

,
C
p

(3 19)
Chen CL 58
A typical correlation function suggested by Equation (3-19) is
Nu = aRe
b
Pr
c
(3 20)
where a, b, and c are parameters that can be determined from experimental data.
A widely used correlation for heat transfer during turbulent ow in pipes is the
Sieder-Tate equation:
Nu = 0.023Re
0.8
Pr
1/3
(/
w
)
0.14
(3 21)
in which a dimensionless viscosity ratio has been added. This ratio (/
w
) is the
viscosity at the mean uid temperature to that at the wall temperature. Table
B-15 gives some of the data reported by Williams and Katz for heat transfer
external to 314-inch outside diameter tubes where the Re, Pr, (/
w
) and Nu
dimensionless numbers have been measured.
(a) Use multiple linear regression to determine the parameter values the functional
forms of Equations (3-20) and (3-21) that represent data of Table B-15.
(b) Repeat part (a) using nonlinear regression.
Chen CL 59
(c) Which functional form and parameter values should be recommended as a
correlation for this data set? Justify your selection.
Solution:
For convenience, let the functional forms of Equations (3-20) and (3-21) be
written as
Nu = a
i
Re
b
i
Pr
c
i
(3 22)
Nu = d
i
Re
e
i
Pr
f
i
Mu
g
i
(3 23)
where i = 1 indicates parameter values from linear regression and i = 2 indicates
parameter values from nonlinear regression. Mu represents the viscosity ratio.
(a) A linear regression of either Equation (3-22) or (3-23) requires a
transformation into a linear form.
ln(Nu) = ln(a
i
) + b
i
ln(Re) + c
i
ln(Pr) (3 24)
ln(Nu) = ln(d
i
) + e
i
ln(Re) + f
i
ln(Pr) + g
i
ln(Mu) (3 25)
(b) Direct nonlinear regressions of both Equations (3-22) and (3-23) can be
completed where the converged values from the linear regressions of part (a) can
be used as initial parameter estimates.
Chen CL 60
function P3_05A1_CCL
clear, clc, format short g, format compact
prob_title = ([ Heat Transfer Correlation - Linear Regr. 1]);
ind_var_name=[\bf Re ];
dep_var_name=[\bf Nu ];
xyData=[5.624018 10.79958 0.8329091
5.852202 11.13605 0.8241754
6.042633 11.34805 0.8197798
5.407172 10.43998 0.8415672
5.17615 10.03889 0.8586616
4.743191 7.186144 5.505332
4.563306 6.836259 5.509388
4.22391 6.249975 5.525453
3.893859 5.846439 5.609472
4.025352 4.811371 7.325149
3.686376 3.988984 7.371489
3.850148 4.437934 7.327123
4.54542 7.130099 4.67656
4.60417 6.928538 5.225747
4.420045 6.142037 6.025866
3.580737 4.00369 7.171657];
X=xyData(:,2:end);
Chen CL 61
y=xyData(:,1);
[m,n]=size(X);
freeparm=input( Input 1 if there is a free par., 0 otherwise );
[Beta, ConfInt,ycal, Var, R2]=MlinReg(X,y,freeparm);
disp([ Results, prob_title]);
Res=[];
if freeparm==0, nparm = n-1; else nparm = n; end
for i=0:nparm
if freeparm, ii=i+1; else ii=i; end
Res=[Res; ii Beta(i+1) ConfInt(i+1)];
end
disp( Parameter No. Beta Conf_int);
disp(Res);
sigmar=0;
Var=0;
for i=1:m
Var=Var+ ((exp(ycal(i))-exp(y(i))))^2;
sigmar=sigmar+((exp(ycal(i))-exp(y(i)))/exp(y(i)))^2;
end
disp([ Variance , num2str(Var/(m-(nparm+1)))]);
disp([ Relative variance , num2str(sigmar/(m-(nparm+1)))]);
plot(y,y-ycal,*,Linewidth,2)
Chen CL 62
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title],FontSize,12) % residual plot
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Beta, ConfInt, ycalc, Var, R2]=MlinReg(X,y,freeparm)
[m,n]=size(X); % m-number of rows, n-number of columns
if freeparm
X=[ones(m,1) X]; % Add column of ones if there is a free parameter
npar=n+1;
else
npar=n;
end
Beta=X\y; % Solve XBeta = Y using QR decomposition
ycalc=X*Beta; % Calculated dependent variable values
Var=((y-ycalc)*(y-ycalc))/(m-npar); % variance
ymean=mean(y);
R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correlation coefficient
% Calculate the confidence intervals
A=X*X;
Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrix
tdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...
Chen CL 63
2.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199...
2.1098 2.1009 2.093 2.086 2.0796 2.0739 2.0687 2.0639...
2.0595 2.0555 2.0518 2.0484 2.0452 2.0423 2.0395 2.0369...
2.0345 2.0322 2.0301 2.0281 2.0262 2.0244 2.0227 2.0211...
2.0195 2.0181 2.0167 2.0154 2.0141]; % 95 percent probability t-distr. values
if (m-npar)>45
t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degrees of freedom > 45
else
t=tdistr95(m-npar);
end
for i=1:npar
ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals
end
Input 1 if there is a free parameter, 0 otherwise > 1
Results, Heat Transfer Correlation - Linear Regr. 1
Parameter No. Beta Conf_int
1 -0.41204 1.3557
2 0.53954 0.11606
3 0.24535 0.11394
Variance 265.5792
Relative variance 0.010278
Chen CL 64
Chen CL 65
function P3_05A2_CCL
clear, clc, format short g, format compact
prob_title = ([ Heat Transfer Correlation - Linear Regr 2]);
ind_var_name=[\bf Re ];
dep_var_name=[\bf Nu ];
xyData=[5.624018 10.79958 0.8329091 -0.0544562
5.852202 11.13605 0.8241754 -0.0470916
6.042633 11.34805 0.8197798 -0.0418642
5.407172 10.43998 0.8415672 -0.058689
5.17615 10.03889 0.8586616 -0.0661398
4.743191 7.186144 5.505332 -0.5242486
4.563306 6.836259 5.509388 -0.5395681
4.22391 6.249975 5.525453 -0.5464528
3.893859 5.846439 5.609472 -1.237874
4.025352 4.811371 7.325149 -1.224176
3.686376 3.988984 7.371489 -1.276543
3.850148 4.437934 7.327123 -1.320507
4.54542 7.130099 4.67656 -0.3229639
4.60417 6.928538 5.225747 -0.491023
4.420045 6.142037 6.025866 -0.6694307
3.580737 4.00369 7.171657 -1.298283];
X=xyData(:,2:end);
Chen CL 66
y=xyData(:,1);
[m,n]=size(X);
freeparm=input( Input 1 if there is a free parameter, 0 otherwise > );
[Beta, ConfInt,ycal, Var, R2]=MlinReg(X,y,freeparm);
disp([ Results, prob_title]);
Res=[];
if freeparm==0, nparm = n-1; else nparm = n; end
for i=0:nparm
if freeparm, ii=i+1; else ii=i; end
Res=[Res; ii Beta(i+1) ConfInt(i+1)];
end
disp( Parameter No. Beta Conf_int);
disp(Res);
sigmar=0;
Var=0;
for i=1:m
Var=Var+ ((exp(ycal(i))-exp(y(i))))^2;
sigmar=sigmar+((exp(ycal(i))-exp(y(i)))/exp(y(i)))^2;
end
disp([ Variance , num2str(Var/(m-(nparm+1)))]);
disp([ Relative variance , num2str(sigmar/(m-(nparm+1)))]);
plot(y,y-ycal,*,Linewidth,2)
Chen CL 67
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title],FontSize,12) % residual plot
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Beta, ConfInt, ycalc, Var, R2]=MlinReg(X,y,freeparm)
[m,n]=size(X); % m-number of rows, n-number of columns
if freeparm
X=[ones(m,1) X]; % Add column of ones if there is a free parameter
npar=n+1;
else
npar=n;
end
Beta=X\y; % Solve XBeta = Y using QR decomposition
ycalc=X*Beta; % Calculated dependent variable values
Var=((y-ycalc)*(y-ycalc))/(m-npar); % variance
ymean=mean(y);
R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correlation coefficient
% Calculate the confidence intervals
A=X*X;
Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrix
tdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...
Chen CL 68
2.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199...
2.1098 2.1009 2.093 2.086 2.0796 2.0739 2.0687 2.0639...
2.0595 2.0555 2.0518 2.0484 2.0452 2.0423 2.0395 2.0369...
2.0345 2.0322 2.0301 2.0281 2.0262 2.0244 2.0227 2.0211...
2.0195 2.0181 2.0167 2.0154 2.0141]; % 95 percent probability t-distr. values
if (m-npar)>45
t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degrees of freedom > 45
else
t=tdistr95(m-npar);
end
for i=1:npar
ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals
end
Input 1 if there is a free parameter, 0 otherwise > 1
Results, Heat Transfer Correlation - Linear Regr 2
Parameter No. Beta Conf_int
1 -0.62602 1.7286
2 0.55883 0.15067
3 0.25237 0.12299
4 -0.067722 0.31632
Variance 234.7091
Chen CL 69
Relative variance 0.011346
Chen CL 70
function P3_05B1_CCL
clear, clc, format short g, format compact
xyData=[277 49000 2.3
348 68600 2.28
421 84800 2.27
223 34200 2.32
177 22900 2.36
114.8 1321 246
95.9 931 247
68.3 518 251
49.1 346 273
56 122.9 1518
39.9 54 1590
47 84.6 1521
94.2 1249 107.4
99.9 1021 186
83.1 465 414
35.9 54.8 1302];
X=xyData(:,2:end);
m=size(X,1); %Determine the number of data points
Y=xyData(:,1);
prob_title = ([ Heat Transfer Correlation - Noninear Regr 1]);
Chen CL 71
dep_var_name=[\bf Nu ];
ind_var_name=[\bf RE];
parm=[0.6623 0.5395 0.2454];
npar=size(parm,2); % Determine the number of the parameters
options=optimset(MaxFunEvals,1000); % Change the default value for MaxFunEvals
Beta=fminsearch(@NonlinFun,parm,options,X,Y); % Find optimal parameters using fminsearch
[f,Ycalc]=NonlinFun(Beta,X,Y); % Compute Y (calculated) at the optimum
disp([ Results, prob_title ]);
Res=[];
for i=1:npar
Res=[Res; i Beta(i)];
end
disp( Parameter No. Value );
disp(Res);
sigmar=0;
Var=0;
for i=1:m
Var=Var+ ((Ycalc(i)-Y(i)))^2;
sigmar=sigmar+((Ycalc(i)-Y(i))/Y(i))^2;
end
disp([ Variance , num2str(Var/(m-npar))]);
disp([ Relative variance , num2str(sigmar/(m-npar))]);
Chen CL 72
plot(Y,Y-Ycalc,*,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title],FontSize,12) % residual plot
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [f,Ycalc]=NonlinFun(parm,X,Y)
a=parm(1);
b=parm(2);
c=parm(3);
for i=1:size(X,1);
Ycalc(i,1)=a*X(i,1)^b*X(i,2)^c;
end
resid(:,1)=Y-Ycalc;
f=resid*resid;
Results, Heat Transfer Correlation - Noninear Regr 1
Parameter No. Value
1 0.16567
2 0.66353
3 0.34136
Variance 68.2755
Chen CL 73
Relative variance 0.016832
Chen CL 74
function P3_05B2_CCL
clear, clc, format short g, format compact
xyData=[277 49000 2.3 0.947
348 68600 2.28 0.954
421 84800 2.27 0.959
223 34200 2.32 0.943
177 22900 2.36 0.936
114.8 1321 246 0.592
95.9 931 247 0.583
68.3 518 251 0.579
49.1 346 273 0.29
56 122.9 1518 0.294
39.9 54 1590 0.279
47 84.6 1521 0.267
94.2 1249 107.4 0.724
99.9 1021 186 0.612
83.1 465 414 0.512
35.9 54.8 1302 0.273];
X=xyData(:,2:end);
m=size(X,1); %Determine the number of data points
Y=xyData(:,1);
prob_title = ([ Heat Transfer Correlation - Noninear Regr 2]);
Chen CL 75
dep_var_name=[\bf Nu ];
ind_var_name=[\bf RE];
parm=[0.5347 0.5588 0.2524 -0.06772];
npar=size(parm,2); % Determine the number of the parameters
options=optimset(MaxFunEvals,1000); % Change the default value for MaxFunEvals
Beta=fminsearch(@NonlinFun,parm,options,X,Y); % Find optimal parameters using fminsearch
[f,Ycalc]=NonlinFun(Beta,X,Y); % Compute Y (calculated) at the optimum
disp([ Results, prob_title ]);
Res=[];
for i=1:npar
Res=[Res; i Beta(i)];
end
disp( Parameter No. Value );
disp(Res);
sigmar=0;
Var=0;
for i=1:m
Var=Var+ ((Ycalc(i)-Y(i)))^2;
sigmar=sigmar+((Ycalc(i)-Y(i))/Y(i))^2;
end
disp([ Variance , num2str(Var/(m-npar))]);
disp([ Relative variance , num2str(sigmar/(m-npar))]);
Chen CL 76
plot(Y,Y-Ycalc,*,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title],FontSize,12) % residual plot
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%%%
function [f,Ycalc]=NonlinFun(parm,X,Y)
a=parm(1);
b=parm(2);
c=parm(3);
d=parm(4);
for i=1:size(X,1);
Ycalc(i,1)=a*X(i,1)^b*X(i,2)^c*X(i,3)^d;
end
resid(:,1)=Y-Ycalc;
f=resid*resid;
Results, Heat Transfer Correlation - Noninear Regr 2
Parameter No. Value
1 0.14915
2 0.67329
3 0.32857
Chen CL 77
4 -0.17765
Variance 66.6846
Relative variance 0.014764
Chen CL 78
Correlation of Binary Activity Coecients
Using Margules Equations
Concepts Utilized: Estimation of parameters in the Margules equations for the
correlation of binary activity coecients.
Numerical Methods: Linear and nonlinear regression, transformation of data for
regression; calculation and comparison of condence intervals, residual plots, and
sum of squares.
Problem Statement:
The Margules equations for correlation of binary activity coecients are

1
= exp

x
2
2
(2B A) + 2x
3
2
(AB)

(3-30)

2
= exp

x
2
1
(2AB) + 2x
3
1
(B A)

(3-31)
where x
l
and x
2
are mole fractions of components 1 and 2, respectively, and
1
and
2
are activity coecients. Parameters A and B are constant for a particular
binary mixture.
Equations (3-30) and (3-31) can be combined to give the excess Gibbs energy
Chen CL 79
expression:
g =
G
E
RT
= x
1
ln(
1
) + x
2
ln(
2
) = x
1
x
2
(Ax
2
+ Bx
1
) (3 32)
Activity coecients at various mole
fractions are available for the benzene
and n-heptane binary system in the
following Table, from which g in
Equation (3-32) can be calculated.
A multiple linear regression without
the free parameter can be used to
estimate the parameter values of A
and B. Another method is to sum
Equations (3-30) and (3-31) and use
nonlinear regression on this sum to
determine A and B.
Activity Coecients for
Benzene(1) and n-Heptane(2)
No. x
1

1

2
1 0.0464 1.2968 0.9985
2 0.0861 1.2798 0.9998
3 0.2004 1.2358 1.0068
4 0.2792 1.1988 1.0159
5 0.3842 1.1598 1.0359
6 0.4857 1.1196 1.0676
7 0.5824 1.0838 1.1096
8 0.6904 1.0538 1.1664
9 0.7842 1.0311 1.2401
10 0.8972 1.0078 1.4038
Chen CL 80
(a) Use multiple linear regression on Equation (3-32) with the data of Table to
determine A and B in the Margules equations for the benzene and n-heptane
binary system.
(b) Estimate A and B by employing nonlinear regression on a single equation that
is the sum of Equations (3-30) and (3-31).
(c) Compare the results of the regressions in (a) and (b) using parameter condence
intervals, residual plots, and sums of squares of errors (least-squares summations
calculated with both activity coecients).
Solution:
Equation (3-32) can be rearranged to a linear form as
g = Ax
2
1
xx
2
+ Bx
1
x
2
2
= a
1
X
1
+ a
2
X
2
Lets create a column for the summation equation, (
1
+
2
), and call it gsum,
as it will provide the function values during the nonlinear regression.
gsum = exp

x
2
2
(2B A) + 2x
3
2
(AB)

+ exp

x
2
1
(2AB) + 2x
3
1
(B A)

Chen CL 81
function P3_08AC_CCL
clear, clc, format short g, format compact
prob_title = ([ Multiple Linear Regression for Par.s of Margules Eq.s]);
ind_var_name=[\bf X1 and X2 ]; dep_var_name=[\bf g ];
xyData=[0.0106279 0.042194 0.0020531
0.0210584 0.0719119 0.0067749
0.0478473 0.1281278 0.0321121
0.0619954 0.1450591 0.0561883
0.0786764 0.1456923 0.090898
0.0885122 0.1284698 0.1213257
0.0902979 0.1015646 0.1416456
0.0838331 0.0661763 0.1475715
0.0704555 0.0365199 0.1327104
0.041839 0.0094815 0.0827507];
x1=[0.0464 0.0861 0.2004 0.2792 0.3842 0.4857 0.5824 0.6904 0.7842
0.8972];
gamma1=[1.2968 1.2798 1.2358 1.1988 1.1598 1.1196 1.0838 1.0538 1.0311
1.0078];
gamma2=[0.9985 0.9998 1.0068 1.0159 1.0359 1.0676 1.1096 1.1664 1.2401
1.4038];
X=xyData(:,2:end);
y=xyData(:,1);
Chen CL 82
[m,n]=size(X);
freeparm=input( Input 1 if there is a free parameter, 0 otherwise > );
[Beta, ConfInt,ycal, Var, R2]=MlinReg(X,y,freeparm);
disp([ Results, prob_title]);
Res=[];
if freeparm==0, nparm = n-1; else nparm = n; end
for i=0:nparm
if freeparm, ii=i+1; else ii=i; end
Res=[Res; ii Beta(i+1) ConfInt(i+1)];
end
disp( Parameter No. Beta Conf_int);
disp(Res);
disp([ Variance , num2str(Var)]);
disp([ Correlation Coefficient , num2str(R2)]);
errsum=0;
for i=1:m
gamma1c(i)= exp((1-x1(i)) ^ 2 * (2 * Beta(2) - Beta(1)) + 2 * (1-x1(i)) ^ 3 * (Beta(1) - Beta(2)));
gamma2c(i)= exp(x1(i) ^ 2 * (2 * Beta(1) - Beta(2)) + 2 * x1(i)^ 3 * (Beta(2) - Beta(1)));
errsum=errsum +(gamma1(i)-gamma1c(i))^2+(gamma2(i)-gamma2c(i))^2;
end
disp([ Sum of squares of errors , num2str(errsum)]);
plot(y,y-ycal,*,Linewidth,2)
Chen CL 83
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title],FontSize,12) % residual plot
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%
function [Beta, ConfInt, ycalc, Var, R2]=MlinReg(X,y,freeparm)
[m,n]=size(X); % m-number of rows, n-number of columns
if freeparm
X=[ones(m,1) X]; % Add column of ones if there is a free parameter
npar=n+1;
else
npar=n;
end
Beta=X\y; % Solve XBeta = Y using QR decomposition
ycalc=X*Beta; % Calculated dependent variable values
Var=((y-ycalc)*(y-ycalc))/(m-npar); % variance
ymean=mean(y);
R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correlation coefficient
% Calculate the confidence intervals
A=X*X;
Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrix
tdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...
Chen CL 84
2.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199...
2.1098 2.1009 2.093 2.086 2.0796 2.0739 2.0687 2.0639...
2.0595 2.0555 2.0518 2.0484 2.0452 2.0423 2.0395 2.0369...
2.0345 2.0322 2.0301 2.0281 2.0262 2.0244 2.0227 2.0211...
2.0195 2.0181 2.0167 2.0154 2.0141]; % 95 percent probability t-distr. values
if (m-npar)>45
t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degrees of freedom > 45
else
t=tdistr95(m-npar);
end
for i=1:npar
ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals
end
Input 1 if there is a free parameter, 0 otherwise > 1
Results, Multiple Linear Regression for Par.s of Margules Eq.s
Parameter No. Beta Conf_int
1 0.00011101 0.0015739
2 0.25048 0.012858
3 0.46044 0.011462
Variance 6.4045e-007
Correlation Coefficient 0.99938
Chen CL 85
Sum of squares of errors 0.2963
Chen CL 86
function P3_08BC_CCL
clear, clc, format short g, format compact
x1=[0.0464 0.0861 0.2004 0.2792 0.3842 0.4857 0.5824 0.6904 0.7842
0.8972];
gamma1=[1.2968 1.2798 1.2358 1.1988 1.1598 1.1196 1.0838 1.0538 1.0311
1.0078];
gamma2=[0.9985 0.9998 1.0068 1.0159 1.0359 1.0676 1.1096 1.1664 1.2401
1.4038];
%xyData=[];
X=x1;
m=size(X,1); %Determine the number of data points
Y=gamma1+gamma2;
prob_title = ([ Nonlinear Regression for Par.s of Margules Eq.s]);
dep_var_name=[\bf gsum ];
ind_var_name=[\bf x1];
parm=[0.25 0.46];
npar=size(parm,2); % Determine the number of the parameters
options=optimset(MaxFunEvals,1000); % Change the default value for MaxFunEvals
Beta=fminsearch(@NonlinFun,parm,options,X,Y); % Find optimal parameters using fminsearch
[f,Ycalc]=NonlinFun(Beta,X,Y); % Compute Y (calculated) at the optimum
disp([ Results, prob_title ]);
Res=[];
Chen CL 87
for i=1:npar
Res=[Res; i Beta(i)];
end
disp( Parameter No. Value );
disp(Res);
s2=sum((Y-Ycalc)*(Y-Ycalc))/(m-npar); %variance
disp([ Variance , num2str(s2)]);
ymean=mean(Y);
R2=(Ycalc-ymean)*(Ycalc-ymean)/((Y-ymean)*(Y-ymean));%linear correlation coefficient
disp([ Correlation Coefficient , num2str(R2)])
errsum=0;
for i=1:m
gamma1c(i)= exp((1-x1(i)) ^ 2 * (2 * Beta(2) - Beta(1)) + 2 * (1-x1(i)) ^ 3 * (Beta(1) - Beta(2)));
gamma2c(i)= exp(x1(i) ^ 2 * (2 * Beta(1) - Beta(2)) + 2 * x1(i)^ 3 * (Beta(2) - Beta(1)));
errsum=errsum +(gamma1(i)-gamma1c(i))^2+(gamma2(i)-gamma2c(i))^2;
end
disp([ Sum of squares of errors , num2str(errsum)]);
subplot(2,1,1)
plot(X,Ycalc,r-,X,Y,bo,Linewidth,2) %Plot of experimental and calculated data
set(gca,FontSize,14,Linewidth,2)
title([\bf Cal/Exp Data prob_title],FontSize,12)
xlabel([ind_var_name],FontSize,14)
Chen CL 88
ylabel([dep_var_name],FontSize,14)
subplot(2,1,2)
plot(Y,Y-Ycalc,*,Linewidth,2) % Residual plot
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title ],FontSize,12)
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%%
function [f,Ycalc]=NonlinFun(parm,X,Y)
A=parm(1);
B=parm(2);
for i=1:size(X,1);
Ycalc(i,1)=exp((1-X(i))^2*(2*B-A)+2*(1-X(i))^3*(A-B))+exp(X(i)^2*(2*A-B)+2*X(i)^3*(B-A));
end
resid(:,1)=Y-Ycalc;
f=resid*resid;
Results, Nonlinear Regression for Par.s of Margules Eq.s
Parameter No. Value
1 0.26077
2 0.45159
Variance 5.2323e-005
Chen CL 89
Correlation Coefficient 0.88483
Sum of squares of errors 0.00079956
Chen CL 90
Regression of Rate Data
checking Dependency Among Variables
Concepts Utilized: Correlation of reaction rate data with various reaction rate
models.
Numerical Methods: Multiple linear regression with determination of parameter
condence intervals, residual plots, and identication of linear dependency among
regression variables.
Problem Statement:
The following Table presents rate data for the reaction A R, as reported by
Bacon and Downie. They suggested tting the rate data with two reaction rate
models. An irreversible model has the form of a rst-order reaction
r
R
= k
0
C
A
(3 38)
and a reversible model has the form of reversible rst-order reactions
r
R
= k
1
C
A
k
2
C
R
(3 39)
Chen CL 91
where r
R
is the rate of generation of component R (gm-mol/dm
3
s); C
A
and C
R
are the respective concentrations of components A and R (gm-mol/dm
3
); and k
0
,
k
l
and k
2
are reaction rate coecients (s
l
).
Reaction Rate Data
No. r
R
C
A
C
R
1 1.25 2.00 7.98
2 2.50 4.00 5.95
3 4.05 6.00 4.00
4 0.75 1.50 8.49
5 2.80 4.00 5.99
6 3.57 5.50 4.50
7 2.86 4.50 5.47
8 3.44 5.00 4.98
9 2.44 4.00 5.99
r
R
: gm-mol/dm
3
s10
8
;
C
A,R
: gm-mol/dm
3
10
4
(a) Calculate the parameters of both
reaction rate expressions using the data
in Table.
(b) Compare the two models and
determine which one better correlates
the rate data.
(c) Determine if the two variables, C
A
and
C
R
, are correlated.
(d) Discuss the practical signicance of
any correlation among the regression
variables.
Chen CL 92
Solution:
P3 11A1 CCL: r
R
= k
0
C
A
P3 11A2 CCL: r
R
= k
1
C
A
k
2
C
R
P3 11B CCL: C
R
= a
0
+ a
1
C
A
Note: C
R
= 0.001 C
A
P3 11D CCL: r
R
= k
1
C
A
k
2
(0.001 C
A
)
= (0.001)k
2
+ (k
1
+ k
2
)C
A
= a
0
+ a
1
C
A
Chen CL 93
% rR = k0 CA
function P3_11A1_CCL
clear, clc, format short g, format compact
prob_title = ([ Regression of Rate Data]);
ind_var_name=[\bf Concentration (g-mol/dm^3 ];
dep_var_name=[\bf Reactoion Rate, g-mol/(dm^3-s) ];
xyData=[1.25E-08 0.0002
2.50E-08 0.0004
4.05E-08 0.0006
7.50E-09 0.00015
2.80E-08 0.0004
3.57E-08 0.00055
2.86E-08 0.00045
3.44E-08 0.0005
2.44E-08 0.0004];
X=xyData(:,2:end);
y=xyData(:,1);
[m,n]=size(X);
freeparm=input( Input 1 if there is a free parameter, 0 otherwise > );
[Beta, ConfInt,ycal, Var, R2]=MlinReg(X,y,freeparm);
disp([ Results, prob_title]);
Res=[];
Chen CL 94
if freeparm==0, nparm = n-1; else nparm = n; end
for i=0:nparm
if freeparm, ii=i+1; else ii=i; end
Res=[Res; ii Beta(i+1) ConfInt(i+1)];
end
disp( Parameter No. Beta Conf_int);
disp(Res);
disp([ Variance , num2str(Var)]);
disp([ Correlation Coefficient , num2str(R2)]);
subplot(2,1,1)
plot(X(:,1),ycal, r-,X(:,1),y,bo,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Cal/Exp Data prob_title],FontSize,12)
xlabel([ind_var_name],FontSize,14)
ylabel([dep_var_name],FontSize,14)
subplot(2,1,2)
plot(y,y-ycal,*,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title],FontSize,12) % residual plot
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Chen CL 95
function [Beta, ConfInt, ycalc, Var, R2]=MlinReg(X,y,freeparm)
[m,n]=size(X); % m-number of rows, n-number of columns
if freeparm
X=[ones(m,1) X]; % Add column of ones if there is a free parameter
npar=n+1;
else
npar=n;
end
Beta=X\y; % Solve XBeta = Y using QR decomposition
ycalc=X*Beta; % Calculated dependent variable values
Var=((y-ycalc)*(y-ycalc))/(m-npar); % variance
ymean=mean(y);
R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correlation coefficient
% Calculate the confidence intervals
A=X*X;
Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrix
tdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...
2.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199...
2.1098 2.1009 2.093 2.086 2.0796 2.0739 2.0687 2.0639...
2.0595 2.0555 2.0518 2.0484 2.0452 2.0423 2.0395 2.0369...
2.0345 2.0322 2.0301 2.0281 2.0262 2.0244 2.0227 2.0211...
2.0195 2.0181 2.0167 2.0154 2.0141]; % 95 percent probability t-distr. values
Chen CL 96
if (m-npar)>45
t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degrees of freedom > 45
else
t=tdistr95(m-npar);
end
for i=1:npar
ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals
end
Input 1 if there is a free parameter, 0 otherwise > 0
Results, Regression of Rate Data
Parameter No. Beta Conf_int
0 6.5514e-005 2.7399e-006
Variance 2.3399e-018
Correlation Coefficient 0.83395
Chen CL 97
Chen CL 98
% rR = k1CA - k2 CR
function P3_11A2_CCL
clear, clc, format short g, format compact
prob_title = ([ Regression of Rate Data]);
ind_var_name=[\bf Concentration (g-mol/dm^3 ];
dep_var_name=[\bf Reaction Rate, g-mol/(dm^3-s) ];
xyData=[1.25E-08 0.0002 0.000798
2.50E-08 0.0004 0.000595
4.05E-08 0.0006 0.0004
7.50E-09 0.00015 0.000849
2.80E-08 0.0004 0.000599
3.57E-08 0.00055 0.00045
2.86E-08 0.00045 0.000547
3.44E-08 0.0005 0.000498
2.44E-08 0.0004 0.000599];
X=xyData(:,2:end);
y=xyData(:,1);
[m,n]=size(X);
freeparm=input( Input 1 if there is a free parameter, 0 otherwise > );
[Beta, ConfInt,ycal, Var, R2]=MlinReg(X,y,freeparm);
disp([ Results, prob_title]);
Res=[];
Chen CL 99
if freeparm==0, nparm = n-1; else nparm = n; end
for i=0:nparm
if freeparm, ii=i+1; else ii=i; end
Res=[Res; ii Beta(i+1) ConfInt(i+1)];
end
disp( Parameter No. Beta Conf_int);
disp(Res);
disp([ Variance , num2str(Var)]);
disp([ Correlation Coefficient , num2str(R2)]);
subplot(2,1,1)
plot(X(:,1),ycal, r-,X(:,1),y,bo,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Cal/Exp Data prob_title],FontSize,12)
xlabel([ind_var_name],FontSize,14)
ylabel([dep_var_name],FontSize,14)
subplot(2,1,2)
plot(y,y-ycal,*,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title],FontSize,12) % residual plot
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%
Chen CL 100
function [Beta, ConfInt, ycalc, Var, R2]=MlinReg(X,y,freeparm)
[m,n]=size(X); % m-number of rows, n-number of columns
if freeparm
X=[ones(m,1) X]; % Add column of ones if there is a free parameter
npar=n+1;
else
npar=n;
end
Beta=X\y; % Solve XBeta = Y using QR decomposition
ycalc=X*Beta; % Calculated dependent variable values
Var=((y-ycalc)*(y-ycalc))/(m-npar); % variance
ymean=mean(y);
R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correlation coefficient
% Calculate the confidence intervals
A=X*X;
Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrix
tdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...
2.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199...
2.1098 2.1009 2.093 2.086 2.0796 2.0739 2.0687 2.0639...
2.0595 2.0555 2.0518 2.0484 2.0452 2.0423 2.0395 2.0369...
2.0345 2.0322 2.0301 2.0281 2.0262 2.0244 2.0227 2.0211...
2.0195 2.0181 2.0167 2.0154 2.0141]; % 95 percent probability t-distr. values
Chen CL 101
if (m-npar)>45
t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degrees of freedom > 45
else
t=tdistr95(m-npar);
end
for i=1:npar
ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals
end
Input 1 if there is a free parameter, 0 otherwise > 0
Results, Regression of Rate Data
Parameter No. Beta Conf_int
0 6.8667e-005 4.5085e-006
1 -2.6304e-006 3.1766e-006
Variance 1.7278e-018
Correlation Coefficient 0.9866
Chen CL 102
Chen CL 103
% CR = a0 + a1 CA
function P3_11B_CCL
clear, clc, format short g, format compact
prob_title = ([ Regression of Rate Data]);
ind_var_name=[\bf CA (g-mol/dm^3) ];
dep_var_name=[\bf CR (g-mol/dm^3) ];
xyData=[0.000798 0.0002
0.000595 0.0004
0.0004 0.0006
0.000849 0.00015
0.000599 0.0004
0.00045 0.00055
0.000547 0.00045
0.000498 0.0005
0.000599 0.0004];
X=xyData(:,2:end);
y=xyData(:,1);
[m,n]=size(X);
freeparm=input( Input 1 if there is a free parameter, 0 otherwise > );
[Beta, ConfInt,ycal, Var, R2]=MlinReg(X,y,freeparm);
disp([ Results, prob_title]);
Res=[];
Chen CL 104
if freeparm==0, nparm = n-1; else nparm = n; end
for i=0:nparm
if freeparm, ii=i+1; else ii=i; end
Res=[Res; ii Beta(i+1) ConfInt(i+1)];
end
disp( Parameter No. Beta Conf_int);
disp(Res);
disp([ Variance , num2str(Var)]);
disp([ Correlation Coefficient , num2str(R2)]);
subplot(2,1,1)
plot(X(:,1),ycal, r-,X(:,1),y,bo,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Cal/Exp Data prob_title],FontSize,12)
xlabel([ind_var_name],FontSize,14)
ylabel([dep_var_name],FontSize,14)
subplot(2,1,2)
plot(y,y-ycal,*,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title],FontSize,12) % residual plot
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%
Chen CL 105
function [Beta, ConfInt, ycalc, Var, R2]=MlinReg(X,y,freeparm)
[m,n]=size(X); % m-number of rows, n-number of columns
if freeparm
X=[ones(m,1) X]; % Add column of ones if there is a free parameter
npar=n+1;
else
npar=n;
end
Beta=X\y; % Solve XBeta = Y using QR decomposition
ycalc=X*Beta; % Calculated dependent variable values
Var=((y-ycalc)*(y-ycalc))/(m-npar); % variance
ymean=mean(y);
R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correlation coefficient
% Calculate the confidence intervals
A=X*X;
Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrix
tdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...
2.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199...
2.1098 2.1009 2.093 2.086 2.0796 2.0739 2.0687 2.0639...
2.0595 2.0555 2.0518 2.0484 2.0452 2.0423 2.0395 2.0369...
2.0345 2.0322 2.0301 2.0281 2.0262 2.0244 2.0227 2.0211...
2.0195 2.0181 2.0167 2.0154 2.0141]; % 95 percent probability t-distr. values
Chen CL 106
if (m-npar)>45
t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degrees of freedom > 45
else
t=tdistr95(m-npar);
end
for i=1:npar
ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals
end
Input 1 if there is a free parameter, 0 otherwise > 1
Results, Regression of Rate Data
Parameter No. Beta Conf_int
1 0.00099746 3.9891e-006
2 -0.99784 0.0092954
Variance 2.7387e-012
Correlation Coefficient 0.99989
Chen CL 107
Chen CL 108
% rR = a0 + a1 CA
function P3_11D_CCL
clear, clc, format short g, format compact
prob_title = ([ Regression of Rate Data]);
ind_var_name=[\bf Concentration (g-mol/dm^3 ];
dep_var_name=[\bf Reaction Rate, g-mol/(dm^3-s) ];
xyData=[1.25E-08 0.0002
2.50E-08 0.0004
4.05E-08 0.0006
7.50E-09 0.00015
2.80E-08 0.0004
3.57E-08 0.00055
2.86E-08 0.00045
3.44E-08 0.0005
2.44E-08 0.0004];
X=xyData(:,2:end);
y=xyData(:,1);
[m,n]=size(X);
freeparm=input( Input 1 if there is a free parameter, 0 otherwise > );
[Beta, ConfInt,ycal, Var, R2]=MlinReg(X,y,freeparm);
disp([ Results, prob_title]);
Res=[];
Chen CL 109
if freeparm==0, nparm = n-1; else nparm = n; end
for i=0:nparm
if freeparm, ii=i+1; else ii=i; end
Res=[Res; ii Beta(i+1) ConfInt(i+1)];
end
disp( Parameter No. Beta Conf_int);
disp(Res);
disp([ Variance , num2str(Var)]);
disp([ Correlation Coefficient , num2str(R2)]);
subplot(2,1,1)
plot(X(:,1),ycal, r-,X(:,1),y,bo,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Cal/Exp Data prob_title],FontSize,12)
xlabel([ind_var_name],FontSize,14)
ylabel([dep_var_name],FontSize,14)
subplot(2,1,2)
plot(y,y-ycal,*,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title],FontSize,12) % residual plot
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%
Chen CL 110
function [Beta, ConfInt, ycalc, Var, R2]=MlinReg(X,y,freeparm)
[m,n]=size(X); % m-number of rows, n-number of columns
if freeparm
X=[ones(m,1) X]; % Add column of ones if there is a free parameter
npar=n+1;
else
npar=n;
end
Beta=X\y; % Solve XBeta = Y using QR decomposition
ycalc=X*Beta; % Calculated dependent variable values
Var=((y-ycalc)*(y-ycalc))/(m-npar); % variance
ymean=mean(y);
R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correlation coefficient
% Calculate the confidence intervals
A=X*X;
Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrix
tdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...
2.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199...
2.1098 2.1009 2.093 2.086 2.0796 2.0739 2.0687 2.0639...
2.0595 2.0555 2.0518 2.0484 2.0452 2.0423 2.0395 2.0369...
2.0345 2.0322 2.0301 2.0281 2.0262 2.0244 2.0227 2.0211...
2.0195 2.0181 2.0167 2.0154 2.0141]; % 95 percent probability t-distr. values
Chen CL 111
if (m-npar)>45
t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degrees of freedom > 45
else
t=tdistr95(m-npar);
end
for i=1:npar
ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals
end
Input 1 if there is a free parameter, 0 otherwise > 1
Results, Regression of Rate Data
Parameter No. Beta Conf_int
1 -2.6263e-009 3.1668e-009
2 7.1298e-005 7.3792e-006
Variance 1.7259e-018
Correlation Coefficient 0.98677
Chen CL 112
Chen CL 113
Calculation of Antoine Equation Parameters
Using Linear Regression
Concepts Utilized: Direct use of the Antoine equation to correlate vapor
pressure versus temperature data.
Numerical Methods: Multiple linear regression with determination of the
overall variance and condence intervals of individual parameters.
Problem Statement:
Calculate the Antoine equation parameters of Equation (3-1) and the various
statistical indicators for the propane vapor pressure data of Table B-5. Report
the parameters for the vapor pressure in psia and the temperature in
o
F. (This
problem is similar to Problem 3.1, but the parameters have dierent units.) The
fundamental calculations for linear regression are to be carried out during the
solution. The following sequence is to be used:
(a) Transform the data so that the Antoine equation parameters can be calculated
using multiple linear regression.
(b) Find the matrices X
T
X and X
T
y.
Chen CL 114
(c) Solve system of equations to obtain the vector A.
(d) Calculate the variance, the diagonal elements of (X
T
y)
l
and the 95% condence
intervals of the parameters (use the t distribution values provided in Table A-
4).
(e) Prepare a residual plot (plot of
i
versus y
i(obs)
).
(f) Assess the precision of the data and the appropriateness of the Antoine equation
for correlation of the data.
Solution:
An alternative linear form of the Antoine equation is
T log(P
v
) = (AC + B) + AT C log(P
v
)
The original data should be entered and transformed into the variables (columns)
shown in Table as specied by y = T log(P
v
), x
1
= T and x
2
= log(P
v
).
Chen CL 115
For the case of multiple linear regression with
two independent variables x
1
and x
2
and one
dependent variable y, the matrix X
T
X and the
vector X
T
y can be written
X
T
X =

x
1,i

x
2,i

x
1,i

x
2
1,i

x
1,i
x
2,i

x
2,i

x
2,i
x
1,i

x
2
2,i

20 500 34.5131
500 79000 1383.28
34.5135 1383.28 63.6854

X
T
y =

y
i(obs)

x
1,i
y
i(obs)

x
2,i
y
i(obs)

1383.28
159281
3339.67

Transformed Variables for the


Antoine Equation Regression
y x
1
x
2
-60.7227 -70 0.867467
-59.26 -60 0.987666
-55.0185 -50 1.10037
-48.3806 -40 1.20952
-39.2249 -30 1.3075
-28.0967 -20 1.40483
-14.9693 -10 1.49693
0. 0 1.58206
16.6276 10 1.66276
34.8859 20 1.74429
54.6454 30 1.82151
75.6838 40 1.89209
98.1421 50 1.96284
121.787 60 2.02979
146.54 70 2.09342
172.378 80 2.15473
199.336 90 2.21484
227.184 100 2.27184
256.122 110 2.32838
285.625 120 2.38021
Chen CL 116
function P3_14_CCL
clear, clc, format short g, format compact
prob_title = ([ Antoine Parameters by Linear Regression]);
ind_var_name=[\bf T (C) ];
dep_var_name=[\bf Tlog(Pv) ];
xyData=[-60.72272 -70. 0.8674675
-59.25998 -60. 0.9876663
-55.01853 -50. 1.100371
-48.3806 -40. 1.209515
-39.22488 -30. 1.307496
-28.06241 -20. 1.403121
-14.9693 -10. 1.49693
0 0 1.582063
16.62758 10. 1.662758
34.88586 20. 1.744293
54.64541 30. 1.821514
75.68378 40. 1.892095
98.14213 50. 1.962843
121.7874 60. 2.029789
146.5395 70. 2.093422
172.3783 80. 2.154728
199.3359 90. 2.214844
Chen CL 117
227.1842 100. 2.271842
256.1218 110. 2.32838
285.6253 120. 2.380211];
X=xyData(:,2:end);
y=xyData(:,1);
[m,n]=size(X);
freeparm=input( Input 1 if there is a free parameter, 0 otherwise > );
[Beta, ConfInt,ycal, Var, R2]=MlinReg(X,y,freeparm);
disp([ Results, prob_title]);
Res=[];
if freeparm==0, nparm = n-1; else nparm = n; end
for i=0:nparm
if freeparm, ii=i+1; else ii=i; end
Res=[Res; ii Beta(i+1) ConfInt(i+1)];
end
disp( Parameter No. Beta Conf_int);
disp(Res);
disp([ Variance , num2str(Var)]);
disp([ Correlation Coefficient , num2str(R2)]);
subplot(2,1,1)
plot(X(:,1),ycal, r-,X(:,1),y,bo,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
Chen CL 118
title([\bf Cal/Exp Data prob_title],FontSize,12)
xlabel([ind_var_name],FontSize,14)
ylabel([dep_var_name],FontSize,14)
subplot(2,1,2)
plot(y,y-ycal,*,Linewidth,2)
set(gca,FontSize,14,Linewidth,2)
title([\bf Residual, prob_title],FontSize,12) % residual plot
xlabel([dep_var_name \bf (Measured)],FontSize,14)
ylabel(\bf Residual,FontSize,14)
%%%%%%%%%%%%%%%%%%%%%%%
function [Beta, ConfInt, ycalc, Var, R2]=MlinReg(X,y,freeparm)
[m,n]=size(X); % m-number of rows, n-number of columns
if freeparm
X=[ones(m,1) X]; % Add column of ones if there is a free parameter
npar=n+1;
else
npar=n;
end
A=X*X
Xty=X*y
Beta=X\y; % Solve XBeta = Y using QR decomposition
ycalc=X*Beta; % Calculated dependent variable values
Chen CL 119
Var=((y-ycalc)*(y-ycalc))/(m-npar); % variance
ymean=mean(y);
R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correlation coefficient
% Calculate the confidence intervals
A=X*X;
Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrix
tdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...
2.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199...
2.1098 2.1009 2.093 2.086 2.0796 2.0739 2.0687 2.0639...
2.0595 2.0555 2.0518 2.0484 2.0452 2.0423 2.0395 2.0369...
2.0345 2.0322 2.0301 2.0281 2.0262 2.0244 2.0227 2.0211...
2.0195 2.0181 2.0167 2.0154 2.0141]; % 95 percent probability t-distr. values
if (m-npar)>45
t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degrees of freedom > 45
else
t=tdistr95(m-npar);
end
for i=1:npar
ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals
end
Chen CL 120
Input 1 if there is a free parameter, 0 otherwise > 1
A =
20 500 34.511
500 79000 1383.3
34.511 1383.3 63.681
Xty =
1383.3
1.5928e+005
3339.8
Results, Antoine Parameters by Linear Regression
Parameter No. Beta Conf_int
1 677.87 7.9544
2 5.2294 0.040941
3 -428.52 5.1958
Variance 0.3301
Correlation Coefficient 0.99998
Chen CL 121
Chen CL 122
Thank You for Your Attention
Questions Are Welcome

También podría gustarte