Sunteți pe pagina 1din 10

ECM6 Computational Methods :

Slide 1 of 8

Lecture 11b
Application of Linear Regression to Kinetic Data
Brian G. Higgins
Department of Chemical Engineering & Materials Science
University of California, Davis
April 2014, Hanoi, Vietnam

ECM6Lecture11dVietnam_2014.nb

Kinetic Expression for Senior Design Project


A few years ago Chem Eng seniors at UCDavis were required to design a process to
produce methanol from synthesis gas (mixture of hydrogen and carbon monoxide). For
their reactor they were given the following rate expression that obeys Langmuir-Hinshelwood kinetics:
R =

k0 H-ERTL JP2H2 PCO -

PMeOH
N
Kp

H1 + K1 PH2 + K2 PCO + K3 PMeOH L3

where Pi is the partial pressure of species i in units of Pa (Pascals) and R is the rate of
reaction in units of Kgmol Is m3 M. Further they are told that KP was fitted to the following
expression
Ln HKp L = -51.8 +

11 824
T

and values of the constants are


E = 66 432.9 J mol, R = 8.314 J mol
They are given experimental data that relates the rate R to temperature, and partial pressures of the species. In order to design the reactor they are required to determine the rate
constants k0 , K1 , K2 , K3 .
Several students were having difficulty fitting the model to the data. In this lecture we will
show how this can be done using a linear regression model. Thus we want to transform
the problem into
Y = a X1 + b X2 + c X3 + d X4
Note that Y and Xi are the new variables and the regression coefficients are
a, b, c, d

ECM6Lecture11dVietnam_2014.nb

Issue of Units
Before we begin our analysis we will check the units of the constants
From the denominator of the rate expression we can deduce that the units of K1 , K2 , and K3 are Pa-1 .
The units of PMeOH Kp must be Pa3 . Thus we can deduce that the units of KP must be Pa-2 . Hence the
numerical value 11824 in the rate expression KP has implied units of K -1 so that the dimensional form of
Kp is given by

KP = I1 -51.8+11 824T M Pa-2

ECM6Lecture11dVietnam_2014.nb

Method : Linearization
Although we can attempt a nonlinear regression to find the constants, it is prudent to try the simplest
approach first, viz, linear regression. In order to use linear regression we need to transform Eq. (1) into
a suitable form. This suggests we write Eq. (1) as

1
R13

H1 + K1 PH2 + K2 PCO + K3 PMeOH L

13
PMeOH
NN
Kp

k13
JH-ERTL JP2H2 PCO 0

H1 + K1 PH2 + K2 PCO + K3 PMeOH L


k0 PZ

where we have defined PZ to be:

PZ =

H-ERTL

P2H2

13

PMeOH

PCO -

Kp

Regrouping terms we can then write our rate expression as

1
R13

PZ
k13
0

K1

P H2

PZ
k13
0

K2

PCO

PZ
k13
0

K3

PMeOH

k13
0

Pz

Next we define the new variables

Y=

1
R13

X1 =

1
PZ

, a=

, X2 =

1
k13
0
P H2
PZ

, b=

, X3 =

K1
k13
0
PCO
PZ

, c=

, X4 =

K2
k13
0

, d=

K3
k13
0

PMeOH
Pz

so that in terms of the new variables our rate expression becomes has the following linear form:

Y = a X1 + b X2 + c X3 + d X4
We can now use linear regression on this expression to determine the parameters a, b, c, d

ECM6Lecture11dVietnam_2014.nb

Mathematica Implementation
Importing the Data
We begin first by importing the data which is in the form of an Excel spreadsheet
In[23]:=

rawData =
First@Import@"TeachingBGHTeaching1ECM6ECM6HomeworkECM6_06DesignData.xls"DD;
rawData TableForm

Out[23]//TableForm=

Run No

TempHKL

R of MeOH Hkgmolsm3L

P of H2HPaL

P of CO HPaL

4.052 10
1.53 106

1.

495.

11.5

8.509 10

2.

495.

11.

8.509 106
6

4.052 10

P of MeOH
253 000.
253 000.

1.013 106

3.

495.

8.33

8.509 10

4.

495.

7.

8.509 106

1.53 106

1.013 106

1.013 106

5.

495.

5.6

5.906 10

6.

495.

5.6

5.906 106

4.052 106

1.013 106

7.

495.

8.4

5.906 106

4.052 106

253 000.

8.

495.

9.

5.906 106

1.53 106

253 000.

6.

8.509 10

4.052 10

9.

475.

10.

475.

5.43

8.509 10

11.

475.

4.33

8.509 106
6

1.53 10

1.53 10

253 000.

4.052 106

1.013 106
1.013 106

475.

3.71

8.509 10

13.

475.

2.86

5.906 106

1.53 106

14.

475.

2.86

5.906 106

4.052 106

4.29

5.906 10

4.052 10

5.906 10

7.091 10

16.
17.

475.
475.
485.

4.67
6.8

1.53 10

1.013 106

12.

15.

1.53 10

253 000.

2.533 10

1.013 106
253 000.
253 000.

507 000.

Reorganizing the Data


It will be convenient to massage the data so that we do not have to deal with headings and spurious
columns like run number and total pressure which are not needed for our linear regression.
Hence we drop the first row (containing the column headings) and drop the first and last columns.
This can be done using the Drop command which operates on rows of a list . So to drop a column we
transpose the data and drop the corresponding row of the transposed matrix. Here is the command
In[24]:=

kineticData = Transpose@Drop@Drop@Transpose@Drop@rawData, 1DD, 1D, - 1DD;

Finally we display the modified data in a table with appropriate headings for the columns

ECM6Lecture11dVietnam_2014.nb

In[25]:=

TableFormAkineticData, TableHeadings
9None, 9"THKL", "RHKgmolHsm3 L", "PH2 HPaL", "PCO HPaL", "PMeOH HPaL"==,
TableAlignments CenterE

Out[25]//TableForm=

THKL

RHKgmolHsm3 L

PH2 HPaL

PCO HPaL

PMeOH HPaL

495.
495.
495.
495.
495.
495.
495.
495.
475.
475.
475.
475.
475.
475.
475.
475.
485.

11.5
11.
8.33
7.
5.6
5.6
8.4
9.
6.
5.43
4.33
3.71
2.86
2.86
4.29
4.67
6.8

8.509 106
8.509 106
8.509 106
8.509 106
5.906 106
5.906 106
5.906 106
5.906 106
8.509 106
8.509 106
8.509 106
8.509 106
5.906 106
5.906 106
5.906 106
5.906 106
7.091 106

4.052 106
1.53 106
4.052 106
1.53 106
1.53 106
4.052 106
4.052 106
1.53 106
4.052 106
1.53 106
4.052 106
1.53 106
1.53 106
4.052 106
4.052 106
1.53 106
2.533 106

253 000.
253 000.
1.013 106
1.013 106
1.013 106
1.013 106
253 000.
253 000.
253 000.
253 000.
1.013 106
1.013 106
1.013 106
1.013 106
253 000.
253 000.
507 000.

The data is now in the appropriate form for using in our least squares regression algorithm.

ECM6Lecture11dVietnam_2014.nb

Regression Analysis
Mathematica Formulation
We begin by defining some auxiliary functions to extract the data. The index i which is patterned match
refers to the run number in the data set.
In[26]:=

PH2 @i_D := kineticData@@i, 3DD; PCO @i_D := kineticData@@i, 4DD;


PMeOH @i_D := kineticData@@i, 5DD; R@i_D := kineticData@@i, 2DD;
T@i_D := kineticData@@i, 1DD; M = Length@kineticDataD;

The variables and parameters for the linearized model are defined as
Y=

X1 =

1
R

13

1
PZ

, a=

, X2 =

1
k0

, b=

P H2
PZ

K1

, c=

k0

, X3 =

PCO
PZ

K2
k0

, d=

, X4 =

K3
k0

PMeOH
Pz

It is convenient to define additionally auxiliary functions for the constant Kp and our new variable PZ
In[27]:=

Kp@i_D := -51.8+11 824T@iD ;


PZ @i_D := H-66 532.9H8.314 T@iDLL PH2 @iD2 PCO @iD -

PMeOH @iD
Kp@iD

13

The definitions for the transformed variables are


In[29]:=

X1 @i_D :=
X3 @i_D :=

1
PZ @iD

; X2 @i_D :=

PCO @iD
PZ @iD

; X4 @i_D :=

PH2 @iD
PZ @iD

PMeOH @iD
PZ @iD

; Y@i_D :=

1
R@iD13

Let us test that all the transformed variables are working for i=2
In[30]:=
Out[30]=

9Y@2D, TableAXj @2D, 8j, 1, 4<E=


80.449644, 80.0000456378, 388.332, 69.8259, 11.5464<<

Next we define a template for our linearized model of the rate expression
In[31]:=

Model1@X1_, X2_, X3_, X4_D := a X1 + b X2 + c X3 + d X4

Note that the variables X1, X2, X3, X4 in the template are pattern matched. Recall in linear regression
we will minimize the sum of squares of the error of (Ypred - Ymeas )
Our Mathematica function for the sum of squares is
M
In[32]:=

E2 @f_, M_D := Hf@X1 @iD, X2 @iD, X3 @iD, X4 @iDD - Y@iDL2


i=1

Note that the variables f and M in the argument of E2 are pattern matched.

ECM6Lecture11dVietnam_2014.nb

Results
To minimize the sum of errors we must find the values of the parameters a,b,c,d such that
E2
a

= 0,

E2
b

= 0,

E2
c

= 0,

E2
d

=0

In the following code we take the derivative of our sum of squares with respect to the parameters and
solve the linear system of equations
In[33]:=

Out[33]=

solModel1 = Solve@8D@E2 @Model1, MD, aD 0, D@E2 @Model1, MD, bD 0,


D@E2 @Model1, MD, cD 0, D@E2 @Model1, MD, dD 0<D Flatten
8a 1744.79, b 0.000641807, c 0.00141122, d 0.00194686<

We can check on the size of the sum of errors by substituting the parameters back into the expression
for the sum of squares
In[34]:=
Out[34]=

E2 @Model1, MD . solModel1
0.000208943

Although we have not done any statistics on the parameters for this regression, the magnitude of E2
suggests we have a reasonable fit
Transforming back to the original parameters we find the following values for our kinetic expression
In[35]:=

Model1params = SolveB
:a ==

Out[35]=

1
k13
0

, b ==

K1
k13
0

, c ==

K2
k13
0

, d ==

K3
k13
0

> . solModel1, 8K1 , K2 , K3 , k0 <F Flatten

9K1 3.67842 10-7 , K2 8.08821 10-7 , K3 1.11581 10-6 , k0 1.88265 10-10 =

ECM6Lecture11dVietnam_2014.nb

Summary of Results
At a minimum w should organize our data in a table to test see how good the fit is. Recall the predicted
function for the rate expression is
k0 H-66 532.9H8.314 T@iDLL JPH2 @iD2 PCO @iD In[36]:=

Rpredict@i_D :=

PMeOH @iD
N
Kp@iD

H1 + K1 PH2 @iD + K2 PCO @iD + K3 PMeOH @iDL3

. Model1params

The index i refers to the run number. Here is a table that compares the measured rate expression with
the predicted rate expression and shows as well the relative error
In[37]:=

TableForm@Table@8i, R@iD, Rpredict@iD, Abs@R@iD - Rpredict@iDD R@iD<, 8i, 1, M<D,


TableHeadings
8None, 8"Run No", "Measured Rate", "Predicted Rate", "Rel Error"<<,
TableAlignments CenterD

Out[37]//TableForm=

Run No
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

Measured Rate
11.5
11.
8.33
7.
5.6
5.6
8.4
9.
6.
5.43
4.33
3.71
2.86
2.86
4.29
4.67
6.8

Predicted Rate
11.5579
10.9826
8.41561
7.15351
5.48624
5.76424
8.28768
9.20565
5.85558
5.57076
4.27292
3.64973
2.82295
2.93597
4.20206
4.67916
6.7699

Rel Error
0.00503824
0.00158377
0.0102774
0.0219294
0.020315
0.0293288
0.0133714
0.0228496
0.0240696
0.0259231
0.0131816
0.0162446
0.0129555
0.0265623
0.0204988
0.00196086
0.00442596

10

ECM6Lecture11dVietnam_2014.nb

Final Comments
Now that we have a good estimate of the parameter values, we are in a position to refine our regression
analysis by doing a nonlinear regression of the data.
In a nonlinear regression we use Newton's method to solve the nonlinear equations that arise from
minimizing the error E2 .
You saw in an earlier lecture that Newton's method will converge quadratically if the initial guess is
close to the fixed point.
Our strategy therefore is to use the linear regression (shown above) to get good initial values for the
rate constants.

S-ar putea să vă placă și