Curve Fitting
Curve Fitting
What is regression?
Regression analysis gives information on the relationship between a response variable
and one or more independent variables to the extent that information is contained in the
data. The goal of regression analysis is to express the response variable as a function of
the predictor variables.
Once regression analysis relationship is obtained, it can be used to predict values of the
response variable, identify variables that most affect response, or verify hypothesized
casual models of the response.
i yi (a 0 a1 xi )
Ideally, if all the residuals i are zero, one may have found an equation in which all
the points lie on the model. Thus, minimization of the residual is an objective of
obtaining regression coefficients.
The most popular method to minimize the residual is the least squares method, where
the estimates of the constants of the models are chosen such that the sum of the squared
n
residuals is minimized, that is minimize i
2
.
i 1
xi , yi
i yi a0 a1 xi xn , y n
x2 , y 2
x3 , y3
x1 , y1 y a0 a1 x
Figure 3.1 Linear regression of y vs. x data showing residuals at a typical point, x i .
Giving
n n n
yi a0 a1 xi 0
i 1 i 1 i 1
n n n
y i xi a0 xi a1 x i2 0
i 1 i 1 i 1
n
Noting that a0 a0 a0 . . . a0 na 0
i 1
n n
na 0 a1 xi yi (3.1)
i 1 i 1
n n n
a0 xi a1 x i2 xi y i (3.2)
i 1 i 1 i 1
Example 3.1
The following y vs. x data is given
x 1 7 13 19 25
y 1 49 169 361 625
y vs x
800
600
y 400
200
0
0 5 10 15 20 25 30
x
Solution
First find the constants of the assumed model
y a0 a1 x
a0 y a1 x
n 5
n 5
xi y i xi y i 1 1 7 49 13 169 19 361 25 625 25025
i 1 i 1
n 5
xi2 xi2 12 7 2 13 2 19 2 25 2 1205
i 1 i 1
n 5
yi yi 1 49 169 361 625 1205
i 1 i 1
_ _
a0 y a1 x
5 25025 65 1205
a1 2
26
5 1205 65
1205 65
a0 y a1 x 26 241 26 13 97
5 5
This gives
y a0 a1 x
y 97 26 x
Example 3.2
The following table gives the value of density of saturated water for various
temperatures of saturated stream.
TempoC ( = T) 100 150 200 250 300
Density kg/m3 (= D) 958 917 865 799 712
b) Find the densities when the temperatures are 130oC and 275oC respectively.
Solution:
a 0 and a 1 can be computed by constructing the following table:
Ti Di Ti 2 T i Di
100 958 10000 95800
150 917 22500 137550
200 865 40000 173000
250 799 62500 199750
300 712 90000 213600
1000 4251 225000 819700
5 819700 1000 4251
a1 - 1.22
5 225000 (1000) 2
4251 1000
a0 a1 1094.2
5 5
D=1094.2-1.22×T
Numerical Analysis /Lec. 2 - 14 -
Fourth Stage
To compare the predicted values to the experimental values:
Ti D i (estimated) Di
D=1094.2-1.22×T
100 958 972.2
150 917 911.2
200 865 850.2
250 799 789.2
300 712 728.2
D(130)= 1094.2-1.22×130=935.6
D(175)= 1094.2-1.22×175=880.7
At the minimum, all the first partial derivatives with respect to ai ’s vanish. We have
N
S
0 2 ( yi a0 a1 xi a2 xi 2 an xi n )( 1) ,
a0 i 1
N
S
0 2 ( yi a0 a1 xi a2 xi 2 an xi n )( xi ) ,
a1 i 1
N
S
0 2 ( yi a0 a1 xi a2 xi 2 an xi n )( xi 2 ) ,
a2 i 1
N
S
0 2 ( yi a0 a1 xi a2 xi 2 an xi n )( xi n ) ,
an i 1
Ti D i (estimated) Di
D=1094.2-1.22×T
100 958 972.2
150 917 911.2
200 865 850.2
250 799 789.2
300 712 728.2
D(130)= 1094.2-1.22×130=935.6
D(175)= 1094.2-1.22×175=880.7
At the minimum, all the first partial derivatives with respect to ai ’s vanish. We have
N
S
0 2 ( yi a0 a1 xi a2 xi 2 an xi n )( 1) ,
a0 i 1
N
S
0 2 ( yi a0 a1 xi a2 xi 2 an xi n )( xi ) ,
a1 i 1
N
S
0 2 ( yi a0 a1 xi a2 xi 2 an xi n )( xi 2 ) ,
a2 i 1
N
S
0 2 ( yi a0 a1 xi a2 xi 2 an xi n )( xi n ) ,
an i 1
N N N N N
a0 xi n a1 xi n 1
a2 xi n 2
an xi 2 n xi n yi ,
i 1 i 1 i 1 i 1 i 1
an
N N N N N
xi n xi n 1
xi n 2
xi 2 n xi n yi
i 1 i 1 i 1 i 1 i 1
Example 3.3
Rotameter calibration data (flow rate versus Rotameter reading) are as follows:
Rotameter Reading R 10 30 50 70 90
Flow rate V(L/min) 20 52.1 84.6 118.3 151
a) Using curve fitting to fit the calibration data to second order polynomial.
b) Calculate the flowrate (V) at rotameter reading R=73.
Solution:
a) 2nd order polynomial
n n
2
Sr i ( yi ao a1 xi a2 xi ) 2
i 1 i 1
n
dS r
2 ( yi ao a1 xi a2 xi2 ) ( 1) 0
dao i 1
n
dS r
2 ( yi ao a1 xi a2 xi2 ) ( xi ) 0 (1)
da1 i 1
n
dS r
2 ( yi ao a1 xi a2 xi2 ) ( xi2 ) 0
da2 i 1
B)
V (73) 3.8786 1.5981 73 4.2857 ×10-4 732 122.83
linear non-linear
Figure 3.2 Linear vs non-linear data
In cases when such linearization of the function is not desirable, or when no method
of linearization can be discovered, graphical methods are frequently used; one merely
plots the experimental values and sketches in a curve that seems to fit well.
Example 3.4
The progress of a homogeneous chemical reaction is followed and it is desired to
evaluate the rate constant and the order of the reaction. The rate law expression for
the reaction is known to follow the power function form r kC n
Use the data provided in the table to obtain n and k .
C A (gmol/l) 4 2.25 1.45 1.0 0.65 0.25 0.006
rA ( gmol/l s) 0.398 0.298 0.238 0.198 0.158 0.098 0.048
Solution
Taking the natural log of both sides of Equation, we obtain
ln r ln k n ln C
Numerical Analysis /Lec. 2 - 19 -
Fourth Stage
Let
z ln r
w ln C
a0 ln(k ) implying that k e a0
a1 n
We get
z a0 a1 w
This is a linear relation between z and w , where
n n n
n wi z i wi zi
i 1 i 1 i 1
a1 2
n n
2
n w i wi
i 1 i 1
n n
zi wi
i 1 i 1
a0 a1
n n
n 7
7
wi 4.3643
i 1
7
zi 12.391
i 1
7
wi z i 16.758
i 1
7
wi2 30.998
i 1
Example 3.5
It is suspected from theoretical considerations that the rate of water flow from a
firehouse is proportional to some power of the nozzle pressure. Assume pressure data
is more accurate. You are transforming the data.
Flow rate, F (gallons/min) 96 129 135 145 168 235
Pressure, p (psi) 11 17 20 25 40 55
b
What is the exponent b of the nozzle pressure in the regression model F ap
Since
n 6
6
x izi ln(11) ln(96) ln(17) ln(129) ln(20) ln(135) ln(25) ln(145) ln(40) ln(168)
i 1
then
6 96.208 19.142 29.890
b
6 62.779 19.1422
577.25 572.15
376.67 366.41
0.49721
0.04
ao ln A 41.2272
A exp(40.2272) 8.0303 1017 0.03
a1 E/R 0.02
E a1 R ( 14612) 8.314 121480 0.01
0
310 315 320 325 330 335
Temperature (K)