+ All Categories
Home > Documents > 12 Regression and Correlation of Data.pdf

12 Regression and Correlation of Data.pdf

Date post: 02-Jun-2018
Category:
Upload: augusto-de-la-cruz-camayo
View: 218 times
Download: 0 times
Share this document with a friend

of 123

Transcript
  • 8/11/2019 12 Regression and Correlation of Data.pdf

    1/123

    Cutlip and Shacham: Problem Solving in Chemical and Biochemical EngineeringChapter 3

    Regression and Correlation of Data

    Cheng-Liang Chen

    P SELABORATORYDepartment of Chemical Engineering

    National TAIWAN University

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    2/123

    Chen CL 1

    Estimation of Antoine Equation ParametersUsing Nonlinear Regression

    Concepts Utilized: Direct use of the Antoine equation to correlate vaporpressure versus temperature data.

    Numerical Methods: Nonlinear regression of a general algebraic expression withdetermination of the overall variance and condence intervals of individualparameters.

    Problem Statement:The Antoine equation is a widely used vapor pressure correlation that utilizes threeparameters, A, B, and C . It is often expressed by

    P v = 10A + B

    T +

    C (3-1)

    where P v is the vapor pressure in mm Hg and T is the temperature in oC.

    Vapor pressure data for propane ( P a ) versus temperature ( K ) is found in TableB-5 in Appendix B. Convert this data set to vapor pressure in mm Hg andtemperature in oC. Then

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    3/123

    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 nonlinearregression 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 beregressed in its nonlinear form. An alternative treatment is to use multiple linear

    regression on the logarithmic form of this equation, but this transformation is notfully suitable, as discussed in Problem 2.8.

    General nonlinear regression can be used to determine the parameters of anexplicit algebraic equation, or model equation, as dened by Equation (3-2):

    y = f (x1 , . . . , x n ; a1 , . . . , a m ) (3-2)

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    4/123

    Chen CL 3

    where the single dependent variable is y, the n independent variables arex1 , . . . , x n , and the m parameters are al , . . . a m . It is usually assumed that theexperimental errors in the preceding equation are normally distributed withconstant variance. Nonlinear regression algorithms determine the parameters for a

    particular model by minimizing the least-squares objective function (L8) given by

    LS =N

    i =1yi (obs) yi (calc)

    where N is the number of data points and (obs) and (calc) refer to observed andcalculated values of the dependent variable.

    The overall estimate of the model variance, 2 , is calculated from

    2 =

    N

    i =1yi (obs) yi (calc)

    = LS

    where is the degrees of freedom, which is equal to the number of data pointsless 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.

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    5/123

    Chen CL 4

    A widely used graphical presentation that indicates any systematic difficulties witha particular model is called the residuals plot. This is simply the error, i , in themodel plotted versus the observed value of the independent variable, yi (obs) withthe error given by

    i = yi (obs) yi (calc)

    Nonlinear Regression of the Antoine Equation The rst step is to enter thedata by assigning a name to each variable (column). The column for the vaporpressure in P a will be designated as P and the column for the temperature in Kwill be denoted as TK. Since the Antoine equation is to correlate the vaporpressure in mm Hg and the temperature in oC, then a new column denoted as Pvand another new column denoted as TC can be created that calculate the pressureand temperature in units of mm Hg and oC by

    Pv = .0075002 P

    TC = TK 273.15

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    6/123

    Chen CL 5

    function P3_01_CCLclear, clc, format short g, format compactxyData=[-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

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    7/123

    Chen CL 6

    6.85 4365.11616.85 5767.65426.85 7485.236.85 9525.254

    46.85 1.2E+0456.85 1.485E+0466.85 1.823E+0476.85 2.213E+0486.85 2.663E+04];

    X=xyData(:,1); m=size(X,1); %Determine the number of data pointsY=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, Cnpar=size(parm,2); % Determine the number of the parametersoptions = optimset(MaxFunEvals,1000); % Change the default value fBeta = fminsearch(@AntFun,parm,options,X,Y); % Find optimal param[f,Ycalc]= AntFun(Beta,X,Y); % Compute Y (calculated) at the optimumdisp( Results, Antoine Eq. Par.s, Nonlinear Regression );

    Res=[];

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    8/123

    Chen CL 7

    for i=1:nparRes=[Res; i Beta(i)];enddisp( Parameter No. Value );

    disp(Res);s2=sum((Y-Ycalc)*(Y-Ycalc))/(m-npar); %variancedisp([ Variance , num2str(s2)]);ymean=mean(Y);R2=(Ycalc-ymean)*(Ycalc-ymean)/((Y-ymean)*(Y-ymean));%linear correldisp([ Correlation Coefficient , num2str(R2)])subplot(2,1,1)

    plot(X,Ycalc,r-,X,Y,b+,LineWidth,2) %Plot of experimental andset(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)

    Ch CL 8

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    9/123

    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));endresid(:,1)=Y-Ycalc;f=resid*resid;

    Results, Antoine Eq. Par.s, Nonlinear RParameter No. Value

    1 7.26442 -1046.33 281.61

    Variance 507.9109Correlation Coefficient 0.99922

    Ch CL 9

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    10/123

    Chen CL 9

    Correlation of Thermodynamic andPhysical 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 linearizationand transformation functions.

    Problem Statement:Tables B-7 through B-10 present values for different 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 TablesB-7 through B-10 using suggested expressions; given in the chemicalengineering literature.

    Solution:Heat Capacity for a Gas Heat capacity for propane gas is given in TableB-7 for temperatures between 50 K and 1500 K. According to Perry et al., the

    Ch CL 10

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    11/123

    Chen CL 10

    heat capacities of gases are most commonly represented as a simple polynomial:

    C p = a0 + a1 T + a2 T 2 + a3 T 3 + . . .

    Thermal Conductivity Thermal conductivity for gaseous propane is given inTable B-8 for the temperature range 231 K to 600 K. Perry et al. note that oversmall temperature ranges the thermal conductivity of low-pressure gases can befairly 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 etal. recommend the correlation of thermal conductivity, k, with T n , where T is theabsolute temperature and n 1.8. This correlation can be directly evaluated withnonlinear 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 Perryet al. is similar to the Antoine equation for vapor pressure:

    log() = A + B/ (T + C )

    Ch CL 11

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    12/123

    Chen CL 11

    where is the viscosity and A, B and C are parameters. If T is expressed inKelvin, parameter C can be approximated by C = 17 .71 0.19T b, where T b is thenormal 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 possiblecorrelation 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 inTable B-10 for the temperature range of 85.47 K to 360 K. Heat of vaporizationcan 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. Theequation can be directly used in nonlinear regression, or it can be linearized bytaking the log of each side yielding

    log( H ) = log( A) + n log(T C T )

    Chen CL 12

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    13/123

    Chen CL 12

    function P3_03A_CCLclear, clc,format short g, format compactprob_title = ([ Heat Cap. of Gaseous Propane]);ind_var_name= [\bf Temperature (K)];

    dep_var_name= [\bf Cp (kJ/kg-mol-K) ];xyData=[ 50 34.06100 41.3150 48.79200 56.07273.16 68.74298.15 73.6300 73.93400 94.01500 112.59600 128.7700 142.67800 154.77900 163.351000 174.61100 182.671200 189.74

    1300 195.85

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    14/123

    Chen CL 14

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    15/123

    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,freeparmtdistr95=[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 probabiif freeparm==1

    n=degree+1;else

    n=degree;end

    m=size(x,1);

    Chen CL 15

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    16/123

    Chen CL 15

    for i=1:mfor j=1:n

    if freeparm==1p=j-1;

    else p=j;end

    X(i,j)=x(i)^p; %Calculate powers of the independent variable and putend

    end

    Beta=X\y; % Solve XBeta = Y using QR decompositionycal=X*Beta; % Calculated dependent variable valuesVar=sum((y-ycal)*(y-ycal))/(m-n); % variance

    if (m-n)>45t=2.07824-0.0017893*(m-n)+0.000008089*(m-n)^2;

    elset=tdistr95(m-n);

    endA=X*X;Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrixfor i=1:n

    ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals

    Chen CL 16

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    17/123

    Chen CL 16

    endymean=mean(y);R2=(ycal-ymean)*(ycal-ymean)/((y-ymean)*(y-ymean));%linear corr

    Input 1 if there is a free parameter, 0 otherwise 1Enter 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 30Results, Heat Capacity of Gaseous Propane

    Parameter No. Beta Conf_int

    0 20.524 4.63861 0.19647 0.0278032 -2.6848e-005 4.2358e-0053 -1.5129e-008 1.8159e-008

    Variance 6.0069Correlation Coefficient 0.99862

    Chen CL 17

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    18/123

    Chen CL 17

    Chen CL 18

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    19/123

    Chen CL 18

    function P3_03B1_CCLclear, clc,format short g, format compactprob_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-02240 1.21E-02260 1.39E-02280 1.59E-02300 1.80E-02

    320 2.02E-02340 2.26E-02360 2.52E-02380 2.78E-02400 3.06E-02420 3.34E-02440 3.63E-02460 3.93E-02480 4.24E-02500 4.55E-02520 4.87E-02

    540 5.20E-02

    Chen CL 19

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    20/123

    Chen CL 19

    560 5.53E-02580 5.86E-02600 6.19E-02];x=xyData(:,1);

    y=xyData(:,2);[m,n]=size(x);freeparm=input( Input 1 if there is a free parameter, 0 otherwisedegree=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; endRes=[Res; ii Beta(i+1) ConfInt(i+1)];

    enddisp( 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

    set(gca,FontSize,14,Linewidth,2)

    Chen CL 20

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    21/123

    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 plotset(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,freeparmtdistr95=[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 probabiif freeparm==1

    n=degree+1;else

    n=degree;

    end

    Chen CL 21

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    22/123

    m=size(x,1);for i=1:m

    for j=1:nif freeparm==1

    p=j-1;elsep=j;

    endX(i,j)=x(i)^p; %Calculate powers of the independent variable and putend

    endBeta=X\y; % Solve XBeta = Y using QR decomposition

    ycal=X*Beta; % Calculated dependent variable valuesVar=sum((y-ycal)*(y-ycal))/(m-n); % variance

    if (m-n)>45t=2.07824-0.0017893*(m-n)+0.000008089*(m-n)^2;

    elset=tdistr95(m-n);

    endA=X*X;Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrix

    for i=1:n

    Chen CL 22

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    23/123

    ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervalsendymean=mean(y);R2=(ycal-ymean)*(ycal-ymean)/((y-ymean)*(y-ymean));%linear corr

    Input 1 if there is a free parameter, 0 otherwise 1Enter 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 31Results, Thermal Conductivity of Gaseous Propane

    Parameter No. Beta Conf_int0 0.0062337 0.000919151 -4.7525e-005 7.2333e-0062 3.4436e-007 1.8141e-0083 -1.8414e-010 1.4585e-011

    Variance 1.1612e-009Correlation Coefficient 1

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    24/123

    Chen CL 24

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    25/123

    function P3_03B2_CCLclear, clc, format short g, format compactxyData=[231.07 1.14E-02240 1.21E-02

    260 1.39E-02280 1.59E-02300 1.80E-02320 2.02E-02340 2.26E-02360 2.52E-02

    380 2.78E-02400 3.06E-02420 3.34E-02440 3.63E-02460 3.93E-02480 4.24E-02500 4.55E-02520 4.87E-02540 5.20E-02560 5.53E-02580 5.86E-02

    600 6.19E-02];

    Chen CL 25

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    26/123

    X=xyData(:,1); m=size(X,1); %Determine the number of data pointsY=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 parametersoptions=optimset(MaxFunEvals,1000); % Change the default value forBeta=fminsearch(@NonlinFun,parm,options,X,Y); % Find optimal paramete

    [f,Ycalc] = NonlinFun(Beta,X,Y); % Compute Y (calculated) at the optidisp([ Results, prob_title ]);Res=[];for i=1:nparRes=[Res; i Beta(i)];enddisp( Parameter No. Value );disp(Res);s2=sum((Y-Ycalc)*(Y-Ycalc))/(m-npar); %variancedisp([ Variance , num2str(s2)]);ymean=mean(Y);

    R2=(Ycalc-ymean)*(Ycalc-ymean)/((Y-ymean)*(Y-ymean));%linear correl

    Chen CL 26

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    27/123

    disp([ Correlation Coefficient , num2str(R2)])subplot(2,1,1)

    plot(X,Ycalc,r-,X,Y,bo,Linewidth,2) %Plot of experimental anset(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;endresid(:,1)=Y-Ycalc;

    f=resid*resid;

    Chen CL 27

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    28/123

    Results, Thermal Conductivity of Gaseous PropaneParameter No. Value

    1 7.2698e-0072 1.7762

    Variance 7.1848e-008Correlation Coefficient 0.9943

    Chen CL 28

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    29/123

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    30/123

    Chen CL 30

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    31/123

    -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; endfor i=0:nparm

    if freeparm, ii=i+1; else ii=i; endRes=[Res; ii Beta(i+1) ConfInt(i+1)];

    enddisp( 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

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    32/123

    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 plotxlabel([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 freeparmX=[ones(m,1) X]; % Add column of ones if there is a free parameternpar=n+1;elsenpar=n;endBeta=X\y; % Solve XBeta = Y using QR decompositionycalc=X*Beta; % Calculated dependent variable valuesVar=((y-ycalc)*(y-ycalc))/(m-npar); % varianceymean=mean(y);R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correl

    % Calculate the confidence intervals

    Chen CL 32

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    33/123

    A=X*X;Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrixtdistr95=[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 probabiif (m-npar)>45

    t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degre

    elset=tdistr95(m-npar);

    endfor i=1:npar

    ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervalsend

    Input 1 if there is a free parameter, 0 otherwise > 1Results, Propane viscosity with Antoine Eq

    Parameter No. Beta Conf_int1 -4.5104 0.067488

    2 159.94 8.9729

    Chen CL 33

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    34/123

    Variance 0.0026888Correlation Coefficient 0.98892

    Chen CL 34

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    35/123

    function P3_03C2_CCLclear, clc, format short g, format compactxyData=[100 3.82E-03110 2.29E-03120 1.53E-03130 1.08E-03140 8.32E-04150 6.59E-04160 5.46E-04170 4.53E-04

    180 3.82E-04190 3.36E-04200 2.87E-04220 2.24E-04240 1.80E-04260 1.44E-04270 1.30E-04280 1.17E-04290 1.05E-04300 9.59E-05];X=xyData(:,1);

    m=size(X,1); %Determine the number of data points

    Chen CL 35

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    36/123

    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 parametersoptions=optimset(MaxFunEvals,1000); % Change the default value forBeta=fminsearch(@AntFun,parm,options,X,Y); % Find optimal parameters[f,Ycalc]=AntFun(Beta,X,Y); % Compute Y (calculated) at the optimumdisp([ Results, prob_title ]);

    Res=[];for i=1:nparRes=[Res; i Beta(i)];enddisp( Parameter No. Value );disp(Res);s2=sum((Y-Ycalc)*(Y-Ycalc))/(m-npar); %variancedisp([ Variance , num2str(s2)]);ymean=mean(Y);R2=(Ycalc-ymean)*(Ycalc-ymean)/((Y-ymean)*(Y-ymean));%linear correldisp([ Correlation Coefficient , num2str(R2)])

    subplot(2,1,1)

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    37/123

    Chen CL 37

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    38/123

    Results, Visc. Propane, Antoine Eq. Params, Nln. RegrParameter No. Value

    1 -4.93792 308.263 23.967

    Variance 0.00047507Correlation Coefficient 0.99816

    Chen CL 38

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    39/123

    Chen CL 39

    f

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    40/123

    function P3_03D1_CCLclear, clc, format short g, format compactprob_title = ([ Propane Heat of Vap., Linear Regr.]);ind_var_name=[\bf log(TC-T)];dep_var_name=[\bf log(deltaH) ];xyData=[7.394452 2.4538697.390935 2.4468947.383815 2.431097.374748 2.4146897.367356 2.397645

    7.359835 2.3799047.352183 2.3614077.344392 2.3420877.33646 2.3218687.32838 2.3006617.320146 2.2783657.311754 2.2548627.303196 2.2300147.294466 2.2036587.285557 2.1755997.274158 2.142264

    7.262451 2.113375

    Chen CL 40

    2 042 2 0 8 66

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    41/123

    7.25042 2.0785667.238046 2.0407217.222716 1.9992617.206826 1.9534217.187521 1.9021667.164353 1.8440427.139879 1.7769197.10721 1.6974917.071882 1.600217.021189 1.474653

    6.951823 1.2973236.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; endfor i=0:nparm

    if freeparm, ii=i+1; else ii=i; end

    Chen CL 41

    f

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    42/123

    Res=[Res; ii Beta(i+1) ConfInt(i+1)];enddisp( 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 plotxlabel([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

    [ ( 1) ] % Add l f if h i f

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    43/123

    X=[ones(m,1) X]; % Add column of ones if there is a free parameternpar=n+1;elsenpar=n;endBeta=X\y; % Solve XBeta = Y using QR decompositionycalc=X*Beta; % Calculated dependent variable valuesVar=((y-ycalc)*(y-ycalc))/(m-npar); % varianceymean=mean(y);R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correl

    % Calculate the confidence intervalsA=X*X;Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrixtdistr95=[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 probabiif (m-npar)>45

    t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degre

    else

    Chen CL 43

    di 95( )

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    44/123

    t=tdistr95(m-npar);endfor i=1:npar

    ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervalsend

    Input 1 if there is a free parameter, 0 otherwise > 1Results, Propane Heat of Vap., Linear Regr.

    Parameter No. Beta Conf_int1 6.4664 0.00761872 0.3765 0.0036327

    Variance 1.1952e-005Correlation Coefficient 0.9994

    Chen CL 44

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    45/123

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    46/123

    Chen CL 46

    280 1 61E+07

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    47/123

    280 1.61E+07290 1.54E+07300 1.46E+07310 1.38E+07320 1.28E+07330 1.18E+07340 1.05E+07350 8.95E+06360 6.81E+06];X=xyData(:,1);

    m=size(X,1); %Determine the number of data pointsY=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 parametersoptions=optimset(MaxFunEvals,1000); % Change the default value forBeta=fminsearch(@NonlinFun,parm,options,X,Y); % Find optimal paramete[f,Ycalc]=NonlinFun(Beta,X,Y); % Compute Y (calculated) at the optimudisp([ Results, prob_title ]);

    Res=[];

    Chen CL 47

    for i=1:npar

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    48/123

    for i=1:nparRes=[Res; i Beta(i)];enddisp( Parameter No. Value );disp(Res);s2=sum((Y-Ycalc)*(Y-Ycalc))/(m-npar); %variancedisp([ Variance , num2str(s2)]);ymean=mean(Y);R2=(Ycalc-ymean)*(Ycalc-ymean)/((Y-ymean)*(Y-ymean));%linear correldisp([ Correlation Coefficient , num2str(R2)])

    subplot(2,1,1)plot(X,Ycalc,r-,X,Y,bo,Linewidth,2) %Plot of experimental an

    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

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    49/123

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%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;endresid(:,1)=Y-Ycalc;f=resid*resid;

    Results, Heat of Vaporization of Propane, NlN Reg.Parameter No. Value

    1 2.9686e+0062 0.37362

    Variance 19016122798.9036Correlation Coefficient 0.99712

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    50/123

    Chen CL 50

    function P3 03D3 CCL

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    51/123

    function P3_03D3_CCLclear, clc,format short g, format compactprob_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+0790 2.46E+07100 2.42E+07110 2.37E+07120 2.33E+07

    130 2.29E+07140 2.25E+07150 2.21E+07160 2.17E+07170 2.13E+07180 2.09E+07190 2.05E+07200 2.01E+07210 1.97E+07220 1.93E+07231.07 1.88E+07

    240 1.83E+07

    Chen CL 51

    250 1 78E+07

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    52/123

    250 1.78E+07260 1.73E+07270 1.67E+07280 1.61E+07290 1.54E+07300 1.46E+07310 1.38E+07320 1.28E+07330 1.18E+07340 1.05E+07

    350 8.95E+06360 6.81E+06];x=xyData(:,1);y=xyData(:,2);[m,n]=size(x);freeparm=input( Input 1 if there is a free parameter, 0 otherwisedegree= 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)];

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    53/123

    Res=[Res; ii Beta(i+1) ConfInt(i+1)];enddisp( 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;

    % endsubplot(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 plotset(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)

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    54/123

    ylabel( \bf Residual , FontSize ,14)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function [Beta, ycal,ConfInt, Var, R2, n]=PolyReg(x,y,degree,freeparmtdistr95=[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 probabiif freeparm==1

    n=degree+1;else

    n=degree;end m=size(x,1);for i=1:m

    for j=1:nif 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

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    55/123

    X(i,j) x(i) p; %Calculate powers of the independent variable and putend

    endBeta=X\y; % Solve XBeta = Y using QR decomposition

    ycal=X*Beta; % Calculated dependent variable valuesVar=sum((y-ycal)*(y-ycal))/(m-n); % variance

    if (m-n)>45t=2.07824-0.0017893*(m-n)+0.000008089*(m-n)^2;

    elset=tdistr95(m-n);

    endA=X*X;Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrixfor i=1:n

    ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervalsendymean=mean(y);R2=(ycal-ymean)*(ycal-ymean)/((y-ymean)*(y-ymean));%linear corr

    Input 1 if there is a free parameter, 0 otherwise 1Enter 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.

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    56/123

    Results may be inaccurate. RCOND 5.894599e 018.> In P3_03D3_CCL>PolyReg at 100

    In P3_03D3_CCL at 40Results, Heat of Vaporization of Propane, Polynomial

    Parameter No. Beta Conf_int0 3.3335e+007 1.5284e+0061 -1.4048e+005 242492 602.57 117.083 -1.1448 0.17534

    Variance 40745270933.3095

    Correlation Coefficient 0.99847

    Chen CL 56

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    57/123

    Chen CL 57

    Heat Transfer Correlations

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    58/123

    Heat Transfer Correlationsfrom Dimensional Analysis

    Concepts Utilized: Correlation of heat transfer data using dimensionless groups.

    Numerical Methods: Linear and nonlinear regression of data with linearizationand use of transformation functions.

    Problem Statement:

    An important tool in the correlation of engineering data is the use of dimensionalanalysis. This treatment leads to the determination of the independentdimensionless numbers, which may be important for a particular problem. Linearand 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 Geankoplisusing the Buckingham method, and the result is that the Nusselt number isexpected to be a function of the Reynolds and Prandtl numbers.

    Nu = f (Re,Pr ) or hD

    k = f

    Dv

    ,

    C p

    k(3 19)

    Chen CL 58

    A typical correlation function suggested by Equation (3-19) is

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    59/123

    A typical correlation function suggested by Equation (3 19) is

    Nu = aRe bP r 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 theSieder-Tate equation:

    Nu = 0 .023Re 0 .8 P r 1 / 3 (/ w )0 .14 (3 21)

    in which a dimensionless viscosity ratio has been added. This ratio (/ w ) is theviscosity at the mean uid temperature to that at the wall temperature. TableB-15 gives some of the data reported by Williams and Katz for heat transferexternal to 314-inch outside diameter tubes where the Re, P r , (/ w ) and Nu

    dimensionless numbers have been measured.

    (a) Use multiple linear regression to determine the parameter values the functionalforms 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

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    60/123

    (c) Which functional form and parameter values should be recommended as acorrelation for this data set? Justify your selection.

    Solution:

    For convenience, let the functional forms of Equations (3-20) and (3-21) bewritten asNu = ai Re bi P r ci (3 22)Nu = di Re e i P r f i Mu gi (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 atransformation into a linear form.

    ln(Nu ) = ln(a i ) + bi ln(Re) + ci ln(P r ) (3 24)

    ln(Nu ) = ln(di ) + ei ln(Re) + f i ln(P r ) + gi ln(Mu ) (3 25)

    (b) Direct nonlinear regressions of both Equations (3-22) and (3-23) can becompleted where the converged values from the linear regressions of part (a) canbe used as initial parameter estimates.

    Chen CL 60function P3_05A1_CCL

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    61/123

    clear, clc, format short g, format compactprob_title = ([ Heat Transfer Correlation - Linear Regr. 1]);ind_var_name=[\bf Re ];dep_var_name=[\bf Nu ];xyData=[5.624018 10.79958 0.83290915.852202 11.13605 0.82417546.042633 11.34805 0.81977985.407172 10.43998 0.84156725.17615 10.03889 0.8586616

    4.743191 7.186144 5.5053324.563306 6.836259 5.5093884.22391 6.249975 5.5254533.893859 5.846439 5.6094724.025352 4.811371 7.3251493.686376 3.988984 7.3714893.850148 4.437934 7.3271234.54542 7.130099 4.676564.60417 6.928538 5.2257474.420045 6.142037 6.0258663.580737 4.00369 7.171657];X=xyData(:,2:end);

    Chen CL 61

    y=xyData(:,1);

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    62/123

    y y ( , );[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; endfor i=0:nparm

    if freeparm, ii=i+1; else ii=i; endRes=[Res; ii Beta(i+1) ConfInt(i+1)];

    enddisp( 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;

    enddisp([ 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)

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    63/123

    (g , , , , )title([\bf Residual, prob_title],FontSize,12) % residual plotxlabel([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 columnsif freeparmX=[ones(m,1) X]; % Add column of ones if there is a free parameternpar=n+1;

    elsenpar=n;endBeta=X\y; % Solve XBeta = Y using QR decompositionycalc=X*Beta; % Calculated dependent variable valuesVar=((y-ycalc)*(y-ycalc))/(m-npar); % varianceymean=mean(y);R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correl% Calculate the confidence intervalsA=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 632.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199..

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    64/123

    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 probabiif (m-npar)>45

    t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degreelse

    t=tdistr95(m-npar);end

    for i=1:nparConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervalsend

    Input 1 if there is a free parameter, 0 otherwise > 1Results, Heat Transfer Correlation - Linear Regr. 1

    Parameter No. Beta Conf_int1 -0.41204 1.35572 0.53954 0.116063 0.24535 0.11394

    Variance 265.5792

    Relative variance 0.010278

    Chen CL 64

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    65/123

    Chen CL 65function P3_05A2_CCL

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    66/123

    clear, clc, format short g, format compactprob_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.05445625.852202 11.13605 0.8241754 -0.04709166.042633 11.34805 0.8197798 -0.04186425.407172 10.43998 0.8415672 -0.0586895.17615 10.03889 0.8586616 -0.0661398

    4.743191 7.186144 5.505332 -0.52424864.563306 6.836259 5.509388 -0.53956814.22391 6.249975 5.525453 -0.54645283.893859 5.846439 5.609472 -1.2378744.025352 4.811371 7.325149 -1.2241763.686376 3.988984 7.371489 -1.2765433.850148 4.437934 7.327123 -1.3205074.54542 7.130099 4.67656 -0.32296394.60417 6.928538 5.225747 -0.4910234.420045 6.142037 6.025866 -0.66943073.580737 4.00369 7.171657 -1.298283];X=xyData(:,2:end);

    Chen CL 66y=xyData(:,1);

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    67/123

    [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; endfor i=0:nparm

    if freeparm, ii=i+1; else ii=i; endRes=[Res; ii Beta(i+1) ConfInt(i+1)];

    enddisp( 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;

    enddisp([ Variance , num2str(Var/(m-(nparm+1)))]);disp([ Relative variance , num2str(sigmar/(m-(nparm+1)))]);plot(y,y-ycal,*,Linewidth,2)

    Chen CL 67set(gca,FontSize,14,Linewidth,2)

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    68/123

    title([\bf Residual, prob_title],FontSize,12) % residual plotxlabel([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 columnsif freeparmX=[ones(m,1) X]; % Add column of ones if there is a free parameternpar=n+1;

    elsenpar=n;endBeta=X\y; % Solve XBeta = Y using QR decompositionycalc=X*Beta; % Calculated dependent variable valuesVar=((y-ycalc)*(y-ycalc))/(m-npar); % varianceymean=mean(y);R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correl% Calculate the confidence intervalsA=X*X;Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrixtdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...

    Chen CL 682.2622 2.2281 2.2010 2.1788 2.1604 2.1448 2.1315 2.1199..

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    69/123

    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 probabiif (m-npar)>45

    t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degreelse

    t=tdistr95(m-npar);end

    for i=1:nparConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervalsend

    Input 1 if there is a free parameter, 0 otherwise > 1Results, Heat Transfer Correlation - Linear Regr 2

    Parameter No. Beta Conf_int1 -0.62602 1.72862 0.55883 0.150673 0.25237 0.122994 -0.067722 0.31632

    Variance 234.7091

    Chen CL 69Relative variance 0.011346

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    70/123

    Chen CL 70function P3_05B1_CCL

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    71/123

    clear, clc, format short g, format compactxyData=[277 49000 2.3348 68600 2.28421 84800 2.27223 34200 2.32177 22900 2.36114.8 1321 24695.9 931 24768.3 518 251

    49.1 346 27356 122.9 151839.9 54 159047 84.6 152194.2 1249 107.499.9 1021 186

    83.1 465 41435.9 54.8 1302];X=xyData(:,2:end); m=size(X,1); %Determine the number of data pointsY=xyData(:,1);prob_title = ([ Heat Transfer Correlation - Noninear Regr 1]);

    Chen CL 71dep_var_name=[\bf Nu ];

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    72/123

    ind_var_name=[\bf RE];parm=[0.6623 0.5395 0.2454];npar=size(parm,2); % Determine the number of the parametersoptions=optimset(MaxFunEvals,1000); % Change the default value forBeta=fminsearch(@NonlinFun,parm,options,X,Y); % Find optimal paramete[f,Ycalc]=NonlinFun(Beta,X,Y); % Compute Y (calculated) at the optimudisp([ Results, prob_title ]);Res=[];for i=1:npar

    Res=[Res; i Beta(i)];enddisp( 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;

    enddisp([ Variance , num2str(Var/(m-npar))]);disp([ Relative variance , num2str(sigmar/(m-npar))]);

    Chen CL 72plot(Y,Y-Ycalc,*,Linewidth,2)

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    73/123

    set(gca,FontSize,14,Linewidth,2)title([\bf Residual, prob_title],FontSize,12) % residual plotxlabel([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;endresid(:,1)=Y-Ycalc;f=resid*resid;

    Results, Heat Transfer Correlation - Noninear Regr 1Parameter No. Value

    1 0.165672 0.663533 0.34136

    Variance 68.2755

    Chen CL 73Relative variance 0.016832

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    74/123

    Chen CL 74function P3_05B2_CCLl l f h f

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    75/123

    clear, clc, format short g, format compactxyData=[277 49000 2.3 0.947348 68600 2.28 0.954421 84800 2.27 0.959223 34200 2.32 0.943177 22900 2.36 0.936114.8 1321 246 0.59295.9 931 247 0.58368.3 518 251 0.579

    49.1 346 273 0.2956 122.9 1518 0.29439.9 54 1590 0.27947 84.6 1521 0.26794.2 1249 107.4 0.72499.9 1021 186 0.612

    83.1 465 414 0.51235.9 54.8 1302 0.273];X=xyData(:,2:end); m=size(X,1); %Determine the number of data pointsY=xyData(:,1);prob_title = ([ Heat Transfer Correlation - Noninear Regr 2]);

    Chen CL 75dep_var_name=[\bf Nu ];i d [\bf RE]

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    76/123

    ind_var_name=[\bf RE];parm=[0.5347 0.5588 0.2524 -0.06772];npar=size(parm,2); % Determine the number of the parametersoptions=optimset(MaxFunEvals,1000); % Change the default value forBeta=fminsearch(@NonlinFun,parm,options,X,Y); % Find optimal paramete[f,Ycalc]=NonlinFun(Beta,X,Y); % Compute Y (calculated) at the optimudisp([ Results, prob_title ]);Res=[];for i=1:npar

    Res=[Res; i Beta(i)];enddisp( 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;

    enddisp([ Variance , num2str(Var/(m-npar))]);disp([ Relative variance , num2str(sigmar/(m-npar))]);

    Chen CL 76plot(Y,Y-Ycalc,*,Linewidth,2)

    ( F Si 14 Li id h 2)

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    77/123

    set(gca,FontSize,14,Linewidth,2)title([\bf Residual, prob_title],FontSize,12) % residual plotxlabel([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;endresid(:,1)=Y-Ycalc;f=resid*resid;

    Results, Heat Transfer Correlation - Noninear Regr 2Parameter No. Value

    1 0.149152 0.67329

    3 0.32857

    Chen CL 774 -0.17765

    Variance 66 6846

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    78/123

    Variance 66.6846Relative variance 0.014764

    Chen CL 78

    Correlation of Binary Activity Coefficients

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    79/123

    Using Margules Equations

    Concepts Utilized: Estimation of parameters in the Margules equations for thecorrelation of binary activity coefficients.

    Numerical Methods: Linear and nonlinear regression, transformation of data forregression; calculation and comparison of condence intervals, residual plots, andsum of squares.

    Problem Statement:The Margules equations for correlation of binary activity coefficients are

    1 = exp x22 (2B A) + 2 x32 (A B ) (3-30) 2 = exp x21 (2A B ) + 2 x31 (B A) (3-31)

    where xl and x2 are mole fractions of components 1 and 2, respectively, and 1and 2 are activity coefficients. Parameters A and B are constant for a particularbinary mixture.

    Equations (3-30) and (3-31) can be combined to give the excess Gibbs energy

    Chen CL 79expression:

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    80/123

    g = GE RT

    = x1 ln( 1 ) + x2 ln( 2 ) = x1 x2 (Ax 2 + Bx 1 ) (3 32)

    Activity coefficients at various molefractions are available for the benzeneand n-heptane binary system in thefollowing Table, from which g inEquation (3-32) can be calculated.A multiple linear regression withoutthe free parameter can be used toestimate the parameter values of A

    and B. Another method is to sumEquations (3-30) and (3-31) and usenonlinear regression on this sum todetermine A and B.

    Activity Coefficients forBenzene(1) and n-Heptane(2)

    No. x1 1 21 0.0464 1.2968 0.9985

    2 0.0861 1.2798 0.99983 0.2004 1.2358 1.00684 0.2792 1.1988 1.01595 0.3842 1.1598 1.0359

    6 0.4857 1.1196 1.06767 0.5824 1.0838 1.10968 0.6904 1.0538 1.16649 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

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    81/123

    determine A and B in the Margules equations for the benzene and n-heptanebinary system.

    (b) Estimate A and B by employing nonlinear regression on a single equation thatis the sum of Equations (3-30) and (3-31).

    (c) Compare the results of the regressions in (a) and (b) using parameter condenceintervals, residual plots, and sums of squares of errors (least-squares summationscalculated with both activity coefficients).

    Solution:Equation (3-32) can be rearranged to a linear form as

    g = Ax 21 xx 2 + Bx 1 x22 = a1 X 1 + a2 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 x22 (2B A) + 2 x32 (A B ) + exp x

    21 (2A B ) + 2 x

    31 (B A)

    Chen CL 81function P3_08AC_CCLclear clc format short g format compact

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    82/123

    clear, clc, format short g, format compactprob_title = ([ Multiple Linear Regression for Par.s of Margules Eq.ind_var_name=[\bf X1 and X2 ]; dep_var_name=[\bf g ];xyData=[0.0106279 0.042194 0.00205310.0210584 0.0719119 0.00677490.0478473 0.1281278 0.03211210.0619954 0.1450591 0.05618830.0786764 0.1456923 0.0908980.0885122 0.1284698 0.1213257

    0.0902979 0.1015646 0.14164560.0838331 0.0661763 0.14757150.0704555 0.0365199 0.13271040.041839 0.0094815 0.0827507];x1=[0.0464 0.0861 0.2004 0.2792 0.3842 0.4857 0.5824 0.6904 0.78420.8972];

    gamma1=[1.2968 1.2798 1.2358 1.1988 1.1598 1.1196 1.0838 1.0538 1.0311.0078];gamma2=[0.9985 0.9998 1.0068 1.0159 1.0359 1.0676 1.1096 1.1664 1.2401.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 >

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    83/123

    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; endfor i=0:nparm

    if freeparm, ii=i+1; else ii=i; endRes=[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-gamma2c(i)= exp(x1(i) ^ 2 * (2 * Beta(1) - Beta(2)) + 2 * x1(i)^errsum=errsum +(gamma1(i)-gamma1c(i)) 2+(gamma2(i)-gamma2c(i))^2

    enddisp([ Sum of squares of errors , num2str(errsum)]);plot(y,y-ycal,*,Linewidth,2)

    Chen CL 83set(gca,FontSize,14,Linewidth,2)

    title([\bf Residual prob title] FontSize 12) % residual plot

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    84/123

    title([ \bf Residual, prob_title], FontSize ,12) % residual plotxlabel([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 columnsif freeparmX=[ones(m,1) X]; % Add column of ones if there is a free parameternpar=n+1;

    elsenpar=n;endBeta=X\y; % Solve XBeta = Y using QR decompositionycalc=X*Beta; % Calculated dependent variable valuesVar=((y-ycalc)*(y-ycalc))/(m-npar); % variance

    ymean=mean(y);R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correl% Calculate the confidence intervalsA=X*X;Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrixtdistr95=[12.7062 4.3027 3.1824 2.7764 2.5706 2.4469 2.3646 2.306...

    Chen CL 842.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

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    85/123

    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 probabiif (m-npar)>45

    t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degreelse

    t=tdistr95(m-npar);end

    for i=1:nparConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervalsend

    Input 1 if there is a free parameter, 0 otherwise > 1Results, Multiple Linear Regression for Par.s of Margules Eq.s

    Parameter No. Beta Conf_int1 0.00011101 0.00157392 0.25048 0.0128583 0.46044 0.011462

    Variance 6.4045e-007

    Correlation Coefficient 0.99938

    Chen CL 85Sum of squares of errors 0.2963

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    86/123

    Chen CL 86function P3_08BC_CCLclear, clc, format short g, format compact

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    87/123

    clear, clc, format short g, format compactx1=[0.0464 0.0861 0.2004 0.2792 0.3842 0.4857 0.5824 0.6904 0.78420.8972];gamma1=[1.2968 1.2798 1.2358 1.1988 1.1598 1.1196 1.0838 1.0538 1.0311.0078];gamma2=[0.9985 0.9998 1.0068 1.0159 1.0359 1.0676 1.1096 1.1664 1.2401.4038];%xyData=[];X=x1;

    m=size(X,1); %Determine the number of data pointsY=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 parametersoptions=optimset(MaxFunEvals,1000); % Change the default value forBeta=fminsearch(@NonlinFun,parm,options,X,Y); % Find optimal paramete[f,Ycalc]=NonlinFun(Beta,X,Y); % Compute Y (calculated) at the optimudisp([ Results, prob_title ]);Res=[];

    Chen CL 87for i=1:nparRes=[Res; i Beta(i)];

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    88/123

    Res [Res; i Beta(i)];enddisp( Parameter No. Value );disp(Res);s2=sum((Y-Ycalc)*(Y-Ycalc))/(m-npar); %variancedisp([ Variance , num2str(s2)]);ymean=mean(Y);R2=(Ycalc-ymean)*(Ycalc-ymean)/((Y-ymean)*(Y-ymean));%linear correldisp([ Correlation Coefficient , num2str(R2)])errsum=0;for i=1:m

    gamma1c(i)= exp((1-x1(i)) ^ 2 * (2 * Beta(2) - Beta(1)) + 2 * (1-gamma2c(i)= exp(x1(i) ^ 2 * (2 * Beta(1) - Beta(2)) + 2 * x1(i)^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 anset(gca,FontSize,14,Linewidth,2)

    title([\bf Cal/Exp Data prob_title],FontSize,12)xlabel([ind_var_name],FontSize,14)

    Chen CL 88ylabel([dep_var_name],FontSize,14)

    subplot(2 1 2)

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    89/123

    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*

    endresid(:,1)=Y-Ycalc;f=resid*resid;

    Results, Nonlinear Regression for Par.s of Margules Eq.sParameter No. Value

    1 0.260772 0.45159

    Variance 5.2323e-005

    Chen CL 89Correlation Coefficient 0.88483Sum of squares of errors 0.00079956

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    90/123

    q

    Chen CL 90

    Regression of Rate Data

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    91/123

    checking Dependency Among Variables

    Concepts Utilized: Correlation of reaction rate data with various reaction ratemodels.

    Numerical Methods: Multiple linear regression with determination of parametercondence intervals, residual plots, and identication of linear dependency amongregression variables.

    Problem Statement:The following Table presents rate data for the reaction A R, as reported byBacon and Downie. They suggested tting the rate data with two reaction ratemodels. An irreversible model has the form of a rst-order reaction

    r R = k0 C A (3 38)

    and a reversible model has the form of reversible rst-order reactions

    r R = k1 C A

    k2 C R (3

    39)

    Chen CL 91

    where rR is the rate of generation of component R (gm-mol/dm 3 s); C A and C Rare the respective concentrations of components A and R (gm-mol/dm 3 ); and k0

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    92/123

    are the respective concentrations of components A and R (gm mol/dm ); and k0 ,kl and k2 are reaction rate coefficients (s

    l).

    Reaction Rate DataNo. rR C A C R

    1 1.25 2.00 7.982 2.50 4.00 5.953 4.05 6.00 4.004 0.75 1.50 8.495 2.80 4.00 5.996 3.57 5.50 4.507 2.86 4.50 5.47

    8 3.44 5.00 4.989 2.44 4.00 5.99

    r R : gm-mol/dm 3 s 108 ;C A,R : gm-mol/dm 3 104

    (a) Calculate the parameters of bothreaction rate expressions using the datain Table.

    (b) Compare the two models and

    determine which one better correlatesthe rate data.

    (c) Determine if the two variables, C A andC R , are correlated.

    (d) Discuss the practical signicance of any correlation among the regressionvariables.

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    93/123

    Chen CL 93

    % rR = k0 CAfunction P3_11A1_CCL

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    94/123

    _ _clear, clc, format short g, format compactprob_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.00022.50E-08 0.00044.05E-08 0.00067.50E-09 0.00015

    2.80E-08 0.00043.57E-08 0.000552.86E-08 0.000453.44E-08 0.00052.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; endfor i=0:nparm

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    95/123

    if freeparm, ii=i+1; else ii=i; endRes=[Res; ii Beta(i+1) ConfInt(i+1)];

    enddisp( 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 plotxlabel([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

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    96/123

    ( )if freeparmX=[ones(m,1) X]; % Add column of ones if there is a free parameternpar=n+1;elsenpar=n;endBeta=X\y; % Solve XBeta = Y using QR decompositionycalc=X*Beta; % Calculated dependent variable values

    Var=((y-ycalc)*(y-ycalc))/(m-npar); % varianceymean=mean(y);R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correl% Calculate the confidence intervalsA=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 probabi

    Chen CL 96

    if (m-npar)>45t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degre

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    97/123

    gelse

    t=tdistr95(m-npar);endfor i=1:npar

    ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervalsend

    Input 1 if there is a free parameter, 0 otherwise > 0

    Results, Regression of Rate DataParameter No. Beta Conf_int

    0 6.5514e-005 2.7399e-006Variance 2.3399e-018Correlation Coefficient 0.83395

    Chen CL 97

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    98/123

    Chen CL 98

    % rR = k1CA - k2 CRfunction P3_11A2_CCL

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    99/123

    clear, clc, format short g, format compactprob_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.0007982.50E-08 0.0004 0.0005954.05E-08 0.0006 0.00047.50E-09 0.00015 0.0008492.80E-08 0.0004 0.0005993.57E-08 0.00055 0.000452.86E-08 0.00045 0.0005473.44E-08 0.0005 0.0004982.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; endfor i=0:nparm

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    100/123

    if freeparm, ii=i+1; else ii=i; endRes=[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 plotxlabel([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

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    101/123

    if freeparmX=[ones(m,1) X]; % Add column of ones if there is a free parameternpar=n+1;elsenpar=n;endBeta=X\y; % Solve XBeta = Y using QR decompositionycalc=X*Beta; % Calculated dependent variable valuesVar=((y-ycalc)*(y-ycalc))/(m-npar); % varianceymean=mean(y);R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correl% Calculate the confidence intervalsA=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 probabi

    Chen CL 101

    if (m-npar)>45t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degre

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    102/123

    elset=tdistr95(m-npar);

    endfor i=1:npar

    ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervalsend

    Input 1 if there is a free parameter, 0 otherwise > 0Results, Regression of Rate Data

    Parameter No. Beta Conf_int0 6.8667e-005 4.5085e-0061 -2.6304e-006 3.1766e-006

    Variance 1.7278e-018Correlation Coefficient 0.9866

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    103/123

    Chen CL 103

    % CR = a0 + a1 CAfunction P3_11B_CCL

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    104/123

    clear, clc, format short g, format compactprob_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.00020.000595 0.00040.0004 0.00060.000849 0.000150.000599 0.00040.00045 0.000550.000547 0.000450.000498 0.00050.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; endfor i=0:nparm

    if f ii i 1 l ii i d

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    105/123

    if freeparm, ii=i+1; else ii=i; endRes=[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 plotxlabel([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

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    106/123

    if freeparmX=[ones(m,1) X]; % Add column of ones if there is a free parameternpar=n+1;elsenpar=n;endBeta=X\y; % Solve XBeta = Y using QR decompositionycalc=X*Beta; % Calculated dependent variable valuesVar=((y-ycalc)*(y-ycalc))/(m-npar); % varianceymean=mean(y);R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correl% Calculate the confidence intervalsA=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 probabi

    Chen CL 106

    if (m-npar)>45t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degre

    l

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    107/123

    elset=tdistr95(m-npar);

    endfor i=1:npar

    ConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervalsend

    Input 1 if there is a free parameter, 0 otherwise > 1Results, Regression of Rate Data

    Parameter No. Beta Conf_int1 0.00099746 3.9891e-0062 -0.99784 0.0092954

    Variance 2.7387e-012Correlation Coefficient 0.99989

    Chen CL 107

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    108/123

    Chen CL 108

    % rR = a0 + a1 CAfunction P3_11D_CCLl l f h f

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    109/123

    clear, clc, format short g, format compactprob_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.00022.50E-08 0.00044.05E-08 0.00067.50E-09 0.000152.80E-08 0.00043.57E-08 0.000552.86E-08 0.000453.44E-08 0.00052.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; endfor i=0:nparm

    if freeparm ii=i+1; else ii=i; end

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    110/123

    if freeparm, ii=i+1; else ii=i; endRes=[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 plotxlabel([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 columnsif f

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    111/123

    if freeparmX=[ones(m,1) X]; % Add column of ones if there is a free parameternpar=n+1;

    elsenpar=n;endBeta=X\y; % Solve XBeta = Y using QR decompositionycalc=X*Beta; % Calculated dependent variable valuesVar=((y-ycalc)*(y-ycalc))/(m-npar); % varianceymean=mean(y);R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correl% Calculate the confidence intervalsA=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 probabi

    Chen CL 111

    if (m-npar)>45t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degre

    else

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    112/123

    elset=tdistr95(m-npar);

    end

    for i=1:nparConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals

    end

    Input 1 if there is a free parameter, 0 otherwise > 1Results, Regression of Rate Data

    Parameter No. Beta Conf_int1 -2.6263e-009 3.1668e-0092 7.1298e-005 7.3792e-006

    Variance 1.7259e-018Correlation Coefficient 0.98677

    Chen CL 112

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    113/123

    Chen CL 113

    Calculation of Antoine Equation ParametersUsing Linear Regression

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    114/123

    Using Linear Regression

    Concepts Utilized: Direct use of the Antoine equation to correlate vaporpressure versus temperature data.

    Numerical Methods: Multiple linear regression with determination of theoverall variance and condence intervals of individual parameters.

    Problem Statement:Calculate the Antoine equation parameters of Equation (3-1) and the variousstatistical indicators for the propane vapor pressure data of Table B-5. Reportthe parameters for the vapor pressure in psia and the temperature in oF. (Thisproblem is similar to Problem 3.1, but the parameters have different units.) Thefundamental 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 calculatedusing 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.

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    115/123

    (d) Calculate the variance, the diagonal elements of (X T y) l and the 95% condenceintervals of the parameters (use the t distribution values provided in Table A-

    4).

    (e) Prepare a residual plot (plot of i versus yi (obs) ).

    (f) Assess the precision of the data and the appropriateness of the Antoine equationfor 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), x1 = T and x2 = log( P v).

    Chen CL 115

    Transformed Variables for theAntoine Equation Regression

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    116/123

    For the case of multiple linear regression withtwo independent variables x1 and x2 and one

    dependent variable y, the matrix X T X and thevector X T y can be written

    X T X =N x1 ,i x2 ,ix1 ,i x21 ,i x1 ,i x2 ,ix2 ,i x2 ,i x1 ,i x22 ,i

    =20 500 34.5131500 79000 1383.28

    34.5135 1383.28 63.6854

    X T y =yi (obs)

    x1 ,i yi (obs)x2 ,i yi (obs)

    =1383.281592813339.67

    y x1 x2-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.5820616.6276 10 1.6627634.8859 20 1.7442954.6454 30 1.8215175.6838 40 1.8920998.1421 50 1.96284

    121.787 60 2.02979146.54 70 2.09342172.378 80 2.15473199.336 90 2.21484227.184 100 2.27184256.122 110 2.32838

    285.625 120 2.38021

    Chen CL 116

    function P3_14_CCLclear, clc, format short g, format compactprob title = ([ Antoine Parameters by Linear Regression]);

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    117/123

    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.58206316.62758 10. 1.66275834.88586 20. 1.74429354.64541 30. 1.821514

    75.68378 40. 1.89209598.14213 50. 1.962843121.7874 60. 2.029789146.5395 70. 2.093422172.3783 80. 2.154728199.3359 90. 2.214844

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    118/123

    Chen CL 118

    title([\bf Cal/Exp Data prob_title],FontSize,12)xlabel([ind_var_name],FontSize,14)ylabel([dep var name] FontSize 14)

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    119/123

    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 plotxlabel([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 columnsif freeparmX=[ones(m,1) X]; % Add column of ones if there is a free parameternpar=n+1;else

    npar=n;endA=X*XXty=X*yBeta=X\y; % Solve XBeta = Y using QR decompositionycalc=X*Beta; % Calculated dependent variable values

    Chen CL 119

    Var=((y-ycalc)*(y-ycalc))/(m-npar); % varianceymean=mean(y);R2=(ycalc-ymean)*(ycalc-ymean)/((y-ymean)*(y-ymean));%linear correl

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    120/123

    R2 (ycalc ymean) (ycalc ymean)/((y ymean) (y ymean));%linear correl% Calculate the confidence intervalsA=X*X;

    Ainv=A\eye(size(A)); %Calculate the inverse of the XX matrixtdistr95=[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 probabiif (m-npar)>45

    t=2.07824-0.0017893*(m-npar)+0.000008089*(m-npar)^2; % t for degreelse

    t=tdistr95(m-npar);

    endfor i=1:nparConfInt(i,1)=t*sqrt(Var*Ainv(i,i)); %confidence intervals

    end

    Chen CL 120

    Input 1 if there is a free parameter, 0 otherwise > 1A =

    20 500 34.511

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    121/123

    20 500 34.511500 79000 1383.3

    34.511 1383.3 63.681

    Xty =1383.3

    1.5928e+0053339.8

    Results, Antoine Parameters by Linear RegressionParameter No. Beta Conf_int

    1 677.87 7.95442 5.2294 0.0409413 -428.52 5.1958

    Variance 0.3301Correlation Coefficient 0.99998

    Chen CL 121

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    122/123

  • 8/11/2019 12 Regression and Correlation of Data.pdf

    123/123


Recommended