skf2133-chapter5n
TRANSCRIPT
-
8/9/2019 skf2133-chapter5n
1/26
Page 5 - 1
Chemical Engineering Numerical Method
copyright PCS- FKKKSA, UTM
Numerical Methods forNumerical Methods for
Chemical EngineersChemical EngineersChapter 5: Curve FittingChapter 5: Curve Fitting
SaharudinSaharudin HaronHaron
-
8/9/2019 skf2133-chapter5n
2/26
Page 5 - 2
Chemical Engineering Numerical Method
copyright PCS- FKKKSA, UTM
Curve FittingCurve Fitting
Data is often given as a discrete values along a continuum and
problems may occur when one need to estimate points between thediscrete 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
-
8/9/2019 skf2133-chapter5n
3/26
-
8/9/2019 skf2133-chapter5n
4/26
Page 5 - 4
Chemical Engineering Numerical Method
copyright PCS- FKKKSA, UTM
Linear Regression Fitting a straight line that represents the general trend of the data.
y = a o
+ a1 x + e
where
e = error or residual n = number of points
( )
x xn
x x
n
x
x x
x x
of meanarithmetic
yof meanarithmeticy yy
intercepta a-ya
slopea -n
y-yn a
i
i
o1o
12i
2i
iiii1
=∑
=
=∑=
==
=∑ ∑
∑ ∑ ∑=
-
8/9/2019 skf2133-chapter5n
5/26
Page 5 - 5
Chemical Engineering Numerical Method
copyright PCS- FKKKSA, UTM
Example 5.1:
Fit a straight line from the Table 1 below.
Table 1
xi 1 2 3 4 5 6 7
yi 0.5 2.5 2.0 4.0 3.5 6.0 5.5
Solution: n = 7 Σ xi yi = 119.5 Σ xi2 = 140 Σ yi = 24 Σ xi = 28
x = 28/7 = 4 a1 = 0.8392857
y = 24/7 = 3.42857 a0 = 0.07142857
Therefore, the least-squares fit is
y = 0.01742857 + 0.8392857x
Linear Regression
x
y
-
8/9/2019 skf2133-chapter5n
6/26
Page 5 - 6
Chemical Engineering Numerical Method
copyright PCS- FKKKSA, UTM
Quantification of Error of Linear Regression Standard deviation, Sy
( )∑ −=−=
2
t
t
y
s
1
S
s
y y
n
i
- the measurement of spread of data around the mean
- the sum of the squares of the residuals between the
data points and the mean
Variance, Sy2 → (standard deviation)2
1
S s t
2
y−
=n
Regression error, Sr
( )∑ ∑= =
==n
1
n
1i
2
i1oi
2
ir xa-a-yesi
- the sum of the squares of the residuals
between the measured and calculated y
-
8/9/2019 skf2133-chapter5n
7/26
Page 5 - 7
Chemical Engineering Numerical Method
copyright PCS- FKKKSA, UTM
Quantification of Error of Linear Regression Standard error of the estimate
2
S
sr
y/ −= n x- the measurement of spread of data around
the regression line
Coefficient of determination
t
r t2S
SS r −= - shows the efficiency of the estimation of spread of the data points using regression line compare to the mean value
tcoefficienncorrelatio- r r
or
2=
i.e. r 2 = 0.923 - indicate that 92.3 % of the original uncertainty has been
explained by the linear model
-
8/9/2019 skf2133-chapter5n
8/26
-
8/9/2019 skf2133-chapter5n
9/26
Page 5 - 9
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:
s y/x = √ [(2.9911 / (7-2)] = 0.7735
Thus because Sy/x < Sy, the linear regression ,model has merit.
r 2 = (St – Sr ) / St = 22.7143 – 2.9911/ (22.7143) = 0.868
or
r = √r 2 = √(0.868)2 = 0.932
The results indicate that 86.8% of original uncertainty has been
explained by the linear model.
-
8/9/2019 skf2133-chapter5n
10/26
-
8/9/2019 skf2133-chapter5n
11/26
-
8/9/2019 skf2133-chapter5n
12/26
Page 5 - 12
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) = a o + a1 x + a 2 x 2 + …….. + a n x
n
• 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:-•Newton’s Interpolating Polynomials
•Lagrange Interpolating Polynomial
•Splines Interpolation
-
8/9/2019 skf2133-chapter5n
13/26
-
8/9/2019 skf2133-chapter5n
14/26
Page 5 - 14
Chemical Engineering Numerical Method
copyright PCS- FKKKSA, UTM
Quadratic (or parabola) Interpolation
Connecting 3 points with a curve.
f 2( x) = b0 + b1( x- x0) + b2( x- x0)( x- x1)
where :
b0
= f( x0)
f( x1) - f( x0)
x1 - x0
f( x2) - f( x1) - f( x1) - f( x0)
x2 - x1 x1 - x0
x2 – x0
b1 = f [ x1, x0] =
b2 = f [ x2, x1, x0] =
-
8/9/2019 skf2133-chapter5n
15/26
Page 5 - 15
Chemical Engineering Numerical Method
copyright PCS- FKKKSA, UTM
Cubic Interpolation (third order)
Connecting 4 points with a curve.
f 3( x) = f( x
0) + ( x- x
0) f[ x
1, x
o] + ( x- x
0)( x- x
1) f [ x
2, x
1, x
o]
+ ( x- x0)( x- x1)( x- x2) f [ x3, x2, x1, xo]
where :
f( x1) - f( x0) x1 - x0
f [ x2, x1] - f [ x1, x0]
x2 - x0
f [ x3 , x2, x1] - f [ x2, x1, x0]
x3
- x0
f [ x1, x0] =
f [ x2
, x1
, x0
] =
f [ x3, x2, x1, x0] =
-
8/9/2019 skf2133-chapter5n
16/26
Page 5 - 16
Chemical Engineering Numerical Method
copyright PCS- FKKKSA, UTM
Newton’s Divided-Difference Interpolating
Polynomials – assignment in class
Table 1 shows the relationship between applied stress and the time tofracture for a stainless steel:
Fracture time, h 5 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/mm
2
. Use Newtoninterpolation of order 3.
-
8/9/2019 skf2133-chapter5n
17/26
Page 5 - 17
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
f n( x) = ∑ Li( x) f ( xi)
i=0
where Li( x) = ∏
≠
= −−n
i j
j ji
j
x x
x x
0
-
8/9/2019 skf2133-chapter5n
18/26
Page 5 - 18
Chemical Engineering Numerical Method
copyright PCS- FKKKSA, UTM
Lagrange Interpolating Polynomials Example :
If n = 1
If n = 2
)()()( 101
00
10
11 x f
x x
x x x f
x x
x x x f
−−+
−−=
)())((
))((
)())((
))(()(
))((
))(()(
21202
10
12101
200
2010
212
x f x x x x
x x x x
x f x x x x
x x x x x f
x x x x
x x x x x f
−−
−−+
−−
−−+
−−
−−=
-
8/9/2019 skf2133-chapter5n
19/26
Page 5 - 19
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.
-
8/9/2019 skf2133-chapter5n
20/26
Page 5 - 20
Chemical Engineering Numerical Method
copyright PCS- FKKKSA, UTM
A set of linear functions can be shown as below :-
f ( x) = f ( x0) + m0( x- x0) x0 ≤ x ≤ x1
f ( x) = f ( x1) + m1( x- x1) x1 ≤ x ≤ x2
:
:
f ( x) = f ( xn-1) + mn-1( x- xn-1) xn-1 ≤ x ≤ xn
where
mi = f ( xi+1) - f ( xi)
xi+1 - xi
Splines Interpolation
-
8/9/2019 skf2133-chapter5n
21/26
Page 5 - 21
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
Solution : For the interval from x = 4.5 to x = 7.0
m = 2.5 - 1.0
7.0 - 4.5
So, f (5) = (1.0) + (0.6)(5.0-4.5)
= 1.3
x f(x)3.0 2.5
4.5 1.0
7.0 2.5
9.0 0.5
= 0.6
-
8/9/2019 skf2133-chapter5n
22/26
Page 5 - 22
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 :
f i(x) = ai x 2 + 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 a’s, b’s and c’s) to evaluate.
-
8/9/2019 skf2133-chapter5n
23/26
Page 5 - 23
Chemical Engineering Numerical Method
copyright PCS- FKKKSA, UTM
Splines Interpolation
The function values must be EQUAL at the interior knots. This conditioncan be represented as :
ai-1 x2
i-1 + bi-1 xi-1 + ci-1 = f ( xi-1)
ai x2 i-1 + bi xi-1 + ci = f ( xi-1)for i = 2 to n.
The first and last functions must pass through the end points.
a1 x20 + b1 x0 + c1 = f ( x0)
an x2n + bn xn + cn = f ( xn)
Conditions that are required to evaluate the unknowns
-
8/9/2019 skf2133-chapter5n
24/26
-
8/9/2019 skf2133-chapter5n
25/26
Page 5 - 25
Chemical Engineering Numerical Method
copyright PCS- FKKKSA, UTM
Splines Interpolation
Cubic Splines
- the objective is to derive a third order polynomial for each interval. f i (x) = ai x
3 + bi x 2 + ci x + d i
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)
-
8/9/2019 skf2133-chapter5n
26/26
Page 5 - 26
Chemical Engineering Numerical Method
copyright PCS- FKKKSA, UTM
Splines Interpolation– assignment in class
Given the data:
x 2 2.5 3 4
f ( x) 5 7 8 2
Predict f (3.4) using linear and quadratic splines.