Sie sind auf Seite 1von 26

Chemical Engineering Numerical Method

copyright PCS- FKKKSA, UTM

Numerical Methods for


Chemical Engineers
Chapter 5: Curve Fitting

Saharudin Haron
Page 5 - 1

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Curve Fitting

Data is often given as a discrete values along a continuum and


problems may occur when one need to estimate points between the
discrete values.

This chapter describes techniques to fit curves to such data to obtain


intermediate estimates.

There are 2 general approaches :


a) Least-squares regression
b) Interpolation

Page 5 - 2

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Least-squares Regression

The strategy is to derive a single curve that represents the general


trend of the data.

No need to intersect every point.

Use to minimizes the discrepancy/differences between the data


points and the curve plotted.

2 types of fitting:
a) Linear regression
b) Polynomial regression

Page 5 - 3

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Linear Regression
Fitting a straight line that represents the general trend of the data.

y = ao + a1x + e
where
e = error or residual

a1 =

n xi y i - xi y i
n x i - ( x i )
2

a o = y - a1 x
yi
n
xi
x=
n

y=

n = number of points
2

a1 = slope
a o = intercept
y = arithmetic mean of y
x = arithmetic mean of x
Page 5 - 4

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Linear Regression

Example 5.1:

Fit a straight line from the Table 1 below.


xi 1
yi 0.5
Solution: n = 7

Table 1
2
3
4
2.5 2.0 4.0

5
3.5

6
6.0

7
5.5

xiyi = 119.5 xi2 = 140 yi = 24 xi = 28


x = 28/7 = 4
y = 24/7 = 3.42857

a1 = 0.8392857
a0 = 0.07142857

Therefore, the least-squares fit is


y = 0.01742857 + 0.8392857x
Page 5 - 5

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Quantification of Error of Linear Regression


Standard deviation, Sy

sy =

St
n 1

- the measurement of spread of data around the mean

s t = ( yi y )

- the sum of the squares of the residuals between the


data points and the mean

Variance, Sy2 (standard deviation)2


2

sy =

St
n 1

Regression error, Sr
n

s r = e = ( y i - a o - a 1x i )
i =1

2
i

i =1

- the sum of the squares of the residuals


between the measured and calculated y
Page 5 - 6

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Quantification of Error of Linear Regression


Standard error of the estimate

s y/x =

Sr
n2

- the measurement of spread of data around


the regression line

Coefficient of determination

r2 =

S t Sr
St

- shows the efficiency of the estimation of spread of the data


points using regression line compare to the mean value

or
r = r2

- correlation coefficient

i.e. r2 = 0.923 - indicate that 92.3 % of the original uncertainty has been
explained by the linear model
Page 5 - 7

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Quantification of Error of Linear Regression


Example 5.2: Estimation of Errors for the Linear Least-Square Fit
Compute the total standard deviation, the standard error of the
estimate, and the correlation coefficient for the data in Example 5.1.
Solution:
xi
1
2
3
4
5
6
7

yi
0.5
2.5
2.0
4.0
3.5
6.0
5.5
24.0

(yi- y )2
8.5765
0.8622
2.0408
0.3265
0.0051
6.6122
4.2908
22.7143

(yi-ao-a1xi)2
0.1687
0.5625
0.3473
0.3265
0.5896
0.7972
0.1993
2.9911
Page 5 - 8

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Quantification of Error of Linear Regression


The standard deviation is:
sy = [(22.7143 / (7 1)] = 1.9457
The standard error is:

sy/x = [(2.9911 / (7-2)] = 0.7735


Thus because Sy/x < Sy, the linear regression ,model has merit.
r2 = (St Sr) / St = 22.7143 2.9911/ (22.7143) = 0.868
or
r = r2 = (0.868)2 = 0.932
The results indicate that 86.8% of original uncertainty has been
explained by the linear model.
Page 5 - 9

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Linear Regression
(assignment in class)
Table 1 shows data of the tensile strength of a plastic versus the heating time.
Time

10

15

20

25

40

50

55

60

75

Tensile
strength

20

18

50

33

48

80

60

78

Table 1
Fit a straight line to this data and calculate the standard deviation, standard
error of the estimate and coefficient of determination of the linear model. Use
the equation to determine the tensile strength at a time of 30 minutes.

Page 5 - 10

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Least-squares Regression
(assignment)
Time

10

15

20

25

30

35

40

45

50

Tensile
strength

25

32

33

38

36

39

40

42

42

Table 1
Use least-squares regression to fit (a) an exponential equation, (b) a power
equation, (c) a saturation-growth-rate equation, and (d) a parabola, to the data
in Table 1. Is any one of the curves superior? If so, justify.

Page 5 - 11

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Interpolation
To estimate intermediate values between precise data points. The most
common method used for this purpose is polynomial interpolation.
General formula for an nth-order polynomial
f(x) = ao + a1x + a2x2 + .. + anxn
Several methods of interpolating polynomials such as :
1st order (linear) connecting 2 points.
2nd order (quadratic or parabolic) connecting 3 points.
3rd order (cubic) connecting 4 points.
The techniques that will be used are:Newtons Interpolating Polynomials
Lagrange Interpolating Polynomial
Splines Interpolation
Page 5 - 12

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Newtons Divided-Difference Interpolating


Polynomials
Linear Interpolation
this technique connecting 2 data points with a straight
line.
f(x)= f(x0) + f(x1) - f(x0)
(x - x0)
x1 - x0
f(x1)
f(x)
f(x0)
x0

x1
Page 5 - 13

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Quadratic (or parabola) Interpolation

Connecting 3 points with a curve.


f2(x) = b0 + b1(x-x0) + b2(x-x0)(x-x1)

where :
b0 = f(x0)

f(x1) - f(x0)
b1 = f [x1, x0] =
x1 - x0

b = f [x , x , x ] =
2
2 1 0

f(x2) - f(x1) - f(x1) - f(x0)


x2 - x1
x1 - x0
x2 x0
Page 5 - 14

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Cubic Interpolation (third order)

Connecting 4 points with a curve.


f3(x) = f(x0) + (x-x0) f[x1,xo] + (x-x0)(x-x1) f [x2, x1,xo]
+ (x-x0)(x-x1)(x-x2) f [x3, x2, x1, xo]

where :

f [x1, x0] =

f(x1) - f(x0)
x1 - x0

f [x2, x1, x0] =

f [x3, x2, x1, x0] =

f [x2, x1] - f [x1, x0]


x2 - x0
f [x3 , x2, x1] - f [x2, x1, x0]
x3 - x0
Page 5 - 15

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Newtons Divided-Difference Interpolating


Polynomials assignment in class
Table 1 shows the relationship between applied stress and the time to
fracture for a stainless steel:
Fracture time, h

10

15

20

25

30

Applied stress,
kg/mm2

11.6

10.3

9.1

8.2

7.4

6.8

Estimate the fracture time for an applied stress of 8.5 kg/mm2. Use Newton
interpolation of order 3.

Page 5 - 16

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Lagrange Interpolating Polynomials


Is a reformulation of the Newton polynomial that avoids the
composition of divided differences.
It can be represented as :
n

fn(x) = Li(x)f(xi)
i=0
n

where

Li(x) =

x xj

xi x j
j =0
j i

Page 5 - 17

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Lagrange Interpolating Polynomials


Example :
If n = 1

x x0
x x1
f ( x0 ) +
f ( x1 )
f1 ( x ) =
x0 x1
x1 x0
If n = 2

f2 ( x) =

( x x0 )( x x2 )
( x x1 )( x x2 )
f ( x0 ) +
f ( x1 )
( x0 x1 )( x0 x2 )
( x1 x0 )( x1 x2 )

( x x0 )( x x1 )
f ( x2 )
( x2 x0 )( x2 x1 )

Page 5 - 18

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Splines Interpolation
3 cases:
Linear Splines
Quadratic Splines
Cubic Splines

Linear Splines
- is a simplest method where a straight line is drawn to connect 2 points.
- a group of ordered data points can be defined as a set of linear functions.

Page 5 - 19

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Splines Interpolation
A set of linear functions can be shown as below :-

f(x) = f(x0) + m0(x-x0)


f(x) = f(x1) + m1(x-x1)
:
:
f(x) = f(xn-1) + mn-1(x-xn-1)

x0 x x1
x1 x x2

xn-1 x xn

where
mi = f(xi+1) - f(xi)
xi+1 - xi
Page 5 - 20

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Splines Interpolation
Example : Fit the data below with first order Splines. Evaluate the
function at x = 5
x
3.0
4.5
7.0
9.0

f(x)
2.5
1.0
2.5
0.5

Solution : For the interval from x = 4.5 to x = 7.0


m = 2.5 - 1.0 = 0.6
7.0 - 4.5
So, f(5) = (1.0) + (0.6)(5.0-4.5)
= 1.3
Page 5 - 21

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Splines Interpolation
Quadratic Splines
the objective in quadratic splines is to derive a second order polynomial
for interval between data points.
The polynomial for each interval can be represented generally as :
fi(x) = ai x2 + bi x + ci - general equation for Quadratic Splines
For n+1 data points, ( i = 0, 1, 2,.n) there are n intervals and
consequently, 3n unknowns constants (the as, bs and cs) to evaluate.

Page 5 - 22

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Splines Interpolation
Conditions that are required to evaluate the unknowns
The function values must be EQUAL at the interior knots. This condition
can be represented as :

ai-1x2 i-1 + bi-1xi-1 + ci-1 = f(xi-1)


aix2 i-1 + bixi-1 + ci = f(xi-1)
for i = 2 to n.
The first and last functions must pass through the end points.

a1x20 + b1x0 + c1 = f(x0)


anx2n + bnxn + cn = f(xn)
Page 5 - 23

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Splines Interpolation
Conditions that are required to evaluate the unknowns
The first derivatives at the interior knots must be equal.

2ai-1x i-1 + bi-1 = 2aixi-1 + bi

for i = 2 to n

Assume that the second derivatives is zero at the first point

a1 = 0

Page 5 - 24

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Splines Interpolation
Cubic Splines
- the objective is to derive a third order polynomial for each interval.

fi (x) = ai x3 + bi x2 + ci x + di
For a quadratic splines, 4n conditions are required to evaluate the
unknowns.These are :

The function values must be equal at the interior knots (2n-2 conditions)
The first and last functions must pass through the end points (2 conditions)
The first derivatives at the interior knots must be equal (n-1 conditions)
The second derivatives at the interior knots must be equal (n-1 conditions)
The second derivatives at the end knots are zero (2 conditions)

Page 5 - 25

Chemical Engineering Numerical Method


copyright PCS- FKKKSA, UTM

Splines Interpolation
assignment in class
Given the data:
x

2.5

f(x)

Predict f(3.4) using linear and quadratic splines.

Page 5 - 26

Das könnte Ihnen auch gefallen