Professional Documents
Culture Documents
Numerical Methods For Chemical Engineers
Numerical Methods For Chemical Engineers
Saharudin Haron
Page 5 - 1
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
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
Linear Regression
Fitting a straight line that represents the general trend of the data.
y = ao + a1x + e
where e = error or residual n = number of points
2
n x i - ( x i ) a o = y - a1 x
2
a1 =
n xi y i - xi y i
yi y= n xi x= n
Example 5.1:
Linear Regression
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
sy =
St n 1
2
- the measurement of spread of data around the mean - the sum of the squares of the residuals between the data points and the mean
s t = ( yi y )
sy =
St n 1
n
Regression error, Sr
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
s y/x =
Sr n2
Coefficient of determination
r2 = or
S t Sr St
- shows the efficiency of the estimation of spread of the data points using regression line compare to the mean value
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
Linear Regression
(assignment in class) Table 1 shows data of the tensile strength of a plastic versus the heating time. Time Tensile strength 10 4 15 20 20 18 25 50 40 33 50 48 55 80 60 60 75 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
Least-squares Regression
(assignment) Time Tensile strength 10 25 15 32 20 33 25 38 30 36 35 39 40 40 45 42 50 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
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
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 x x1
Page 5 - 13
where : b0 = f(x0) f(x1) - f(x0) b1 = f [x1, x0] = x1 - x0 f(x2) - f(x1) - f(x1) - f(x0) x2 - x1 x1 - x0 x2 x0
Page 5 - 14
b = f [x , x , x ] = 2 2 1 0
where :
f [x1, x0] =
f(x1) - f(x0) x1 - x0 f [x2, x1] - f [x1, x0] x2 - x0 f [x3 , x2, x1] - f [x2, x1, x0] x3 - x0
Page 5 - 15
Estimate the fracture time for an applied stress of 8.5 kg/mm2. Use Newton interpolation of order 3.
Page 5 - 16
fn(x) = Li(x)f(xi)
i=0
where
Li(x) =
xi x j
j =0 j i
Page 5 - 17
x xj
f1 ( x ) =
x x0 x x1 f ( x0 ) + f ( x1 ) 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
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
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) where mi = f(xi+1) - f(xi) xi+1 - xi
x0 x x1 x1 x x2
xn-1 x xn
Page 5 - 20
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
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
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 :
Splines Interpolation
Conditions that are required to evaluate the unknowns
The first derivatives at the interior knots must be equal.
for i = 2 to n
a1 = 0
Page 5 - 24
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
Splines Interpolation
assignment in class
Given the data:
x f(x) 2 5 2.5 7 3 8 4 2
Page 5 - 26