Komputasi TK Kuliah 1 Genap1213
Komputasi TK Kuliah 1 Genap1213
Komputasi TK Kuliah 1 Genap1213
Department of Chemical Engineering Faculty of Industrial Technology Parahyangan Catholic University January 2013
Main Aim
To learn about some numerical methods to be used in solving Chemical Engineering Problems. To introduce MATLAB as a tool to solve problems in Chemical Engineering. To apply the numerical methods in MATLAB
1/28/2013
1/28/2013
Grading
Solution of linear Equations Least Squares curve fitting Solution of ordinary differential equations Solution of Partial differential equations
1/28/2013
x = 1 and
x = 3
2x
+ 5 = 0 No analytic x = ex
7
solution
1/28/2013
But Cramer' s Rule is not practical for large problems. To solve N equations with N unknowns, we need (N + 1)(N 1)N! multiplications. To solve a 30 by 30 system, 2.3 1035 multiplications are needed. A super computer needs more than 10 20 years to compute this.
10
1/28/2013
11
Curve Fitting
Given a set of data:
x y 0 0.5 1 10.3 2 21.3
Select a curve that best fits the data. One choice is to find the curve so that the sum of the square of the error is minimized.
12
1/28/2013
Interpolation
Given a set of data:
xi yi 0 0.5 1 10.3 2 15.3
Find a polynomial P(x) whose graph passes through all tabulated points.
13
yi = P ( xi ) if xi is in the table
o Interpolation
o Newton Polynomial Interpolation o Lagrange Interpolation
14
1/28/2013
2u
2
2u
2
+2=0
16
1/28/2013
Text Books
John H. Mathews, Kurtis D. Fink, Numerical Methods With MATLAB, Prentice Hall, NJ, 1999. Steven Chapra, Raymond Canale, Numerical Methods For Engineers,McGrawHill,2010 Michael B. Cutlip, Mordechai Shacham, Problem solving in Chemical Engineering With Numerical Methods, Prentice Hall,NJ,1999. Kenneth J Beers, Numerical Methods for Chemical Engineers, Cambridge Univ Press, Edinburgh, 2007 Alkis Constantinides, Navid Mostoufi, Numerical Methods for Chemical Engineers with MATLAB Applications,Prentice Hall,NJ,1999
1/28/2013
Numerical Methods
10
1/28/2013
11
1/28/2013
Mathematical Modeling
Mathematical Model
A formulation or equation that expresses the essential features of a physical system or process in mathematical terms. Generally, it can be represented as a functional relationship of the form
12
1/28/2013
Mathematical Modeling
13
1/28/2013
qf
d [ m ( t )] = [ q f q ( t )] dt d [ Ah ( t )] = [ q f q ( t )] dt dh ( t ) A = q f kh ( t ) dt q dh ( t ) A + h (t ) = K ; = , K = f dt k k
h h(0)=0
q=kh
qf : inlet volumetric flowrate q : outlet volumetric flowrate
Analytical solution
Solving the differential equations, it gives
hs=K
h(t)
14
1/28/2013
Numerical solution
dh(t ) 1 = [ K h(t )] dt
New Value
Old Value
Step Size
15
1/28/2013
Pre-computer era
computer era
16
1/28/2013
How confident we are in our approximate result? The question is how much error is present in our calculation and is it tolerable?
Chapter 3 34
17
1/28/2013
Error Definition
Numerical errors arise from the use of approximations Errors
Truncation errors Result when approximations are used to represent exact mathematical procedure.
Round-off errors Result when numbers having limited significant figures are used to represent exact numbers.
18
1/28/2013
Round-off Errors
Numbers such as , e, or 7 cannot be expressed by a fixed number of significant figures. Computers use a base-2 representation, they cannot precisely represent certain exact base-10 numbers Example:
= 3.14159265358 to be stored carrying 7 significant digits. = 3.141592 chopping = 3.141593 rounding
Truncation Errors
Truncation errors are those that result using approximation in place of an exact mathematical procedure.
dv v V (t i +1 ) V (t i ) = dt t t i +1 t i
19
1/28/2013
True Error
True error (Et) True error (Et) or Exact value of error = true value approximated value True percent relative error ( t )
True percent relative error = t = True error 100 (%) True value true value approximated value = 100 (%) true value
Example
20
1/28/2013
Example
Approximate Error
The true error is known only when we deal with functions that can be solved analytically. In many applications, a prior true value is rarely available. For this situation, an alternative is to calculate an approximation of the error using the best available estimate of the true value as:
Approximat e error 100 (%) approximat ion
21
1/28/2013
Approximate Error
In many numerical methods a present approximation is calculated using previous approximation:
a =
Note: - The sign of a or t may be positive or negative - We interested in whether the absolute value is lower than a prespecified tolerance (s), not to the sign of error. Thus, the computation is repeated until (stopping criteria):
a < s
Prespecified Error We can relate (s) to the number of significant figures in the approximation, So, we can assure that the result is correct to at least n significant figures if the following criteria is met:
s = (0.5 10 2 n ) %
22
1/28/2013
Example
The exponential function can be computed using Maclaurin series as follows: 2 3 n
e x = 1+ x + x x x + +L+ 2! 3! n!
Estimate e0.5 using series, add terms until the absolute value of approximate error a fall below a pre-specified error s conforming with three significant figures.
{The exact value of e0.5=1.648721}
Solution
s = ( 0.5 1023 ) % = 0.05%
e 0.5 = 1
t =
t =
a =
t =
1.648721 1.625 1.625 1.0 100% = 1.44% a = 100% = 7.69% 1.648721 1.625
Terms 1 2 3 4 5 6
t%
39.3 9.02 1.44 0.175 0.0172 0.00142
a%
--33.3 7.69 1.27 0.158 0.0158
23
1/28/2013
Taylor Series
Motivation
We can easily compute expressions like:
3 10 2 2( x + 4) But, How do you compute 4.1, sin(0.6) ?
b
0.6
48
24
1/28/2013
Taylor Series
The Taylor series expansion of f ( x ) about a : f (a ) + f ' (a ) ( x a ) + or Taylor Series = f ( 2) (a ) f ( 3) ( a ) ( x a )2 + ( x a ) 3 + ... 2! 3!
k =0
1 (k ) f (a ) ( x a )k k!
k =0
Use zero-order to fourth-order Taylor series expansions to approximate the function. f(x)= -0.1x4 0.15x3 0.5x2 0.25x +1.2 From xi = 0 with h =1. Predict the functions value at xi+1 =1. Solution f(xi)= f(0)= 1.2 ,
f(x)= -0.4x3 0.45x2 x 0.25, f(0)= -0.25 f( xi+1)= 1.2- 0.25h = 0.95 Et = 0.2 - 0.95 = -0.75
50
1 (k ) f (a ) ( x a )k k!
49
f ( x i +1 ) = f ( x i )
25
1/28/2013
f(x) = -1.2 x2 0.9x -1 , f(0)= -1 f( xi+1)= 1.2 - 0.25h - 0.5 h2 = 0.45 Et = 0.2 0.45 = -0.25 Third-order approximation (n=3) f(xi+1)= 0.3 f ( x i +1 ) = f ( x i ) + f ' ( x i )h + f( xi+1)= 1.2 - 0.25h - 0.5 h2 0.15h3 = 0.3 Et = 0.2 0.3 = -0.1
51
f ' ' ( x i ) h 2 f ) 3( ( x i ) h 3 + 2! 3!
f(xi+1)= 0.2
f ' ' ( x i ) h 2 f ( 3) ( x i ) h 3 f ( 4 ) ( x i ) h 4 + + 2! 3! 4!
f( xi+1)= 1.2 - 0.25h - 0.5 h2 0.15h3 0.1h 4= 0.2 Et = 0.2 0.2 = 0 f (5) ( ) 5 R4 = h The remainder term (R4) = 0 5! because the fifth derivative of the fourth-order polynomial is zero.
52
26
1/28/2013
53
Taylor Series
In General, the n-th order Taylor Series will be exact for n-th order polynomial. For other differentiable and continuous functions, such as exponentials and sinusoids, a finite number of terms will not yield an exact estimate. Each additional term will contribute some improvement.
54
27
1/28/2013
Maclaurin Series
Maclaurin series is a special case of Taylor series with the center of expansion a = 0.
The Maclauri n series expansion of f ( x ) : f ( 2 ) (0) 2 f ( 3) (0) 3 f ( 0) + f ( 0) x + x + x + ... 2! 3! If the series converge, we can write :
'
f ( x) =
k =0
1 (k ) f ( 0) x k k!
55
k =0
1 k ! f ( k ) ( 0) x k =
k =0
28
1/28/2013
Taylor Series
Example 1
exp(x) 1+x+0.5x 2
2.5
2 1+x 1.5
0.5
0 -1
-0.8
-0.6
-0.4
-0.2
0.2
0.4
0.6
0.8
57
f ( 0) = 0 f ' ( 0) = 1 f ( 2 ) ( 0) = 0 f ( 3) (0) = 1
29
1/28/2013
sin(x)
x-x 3/3!
-3
-2
-1
59
60
30
1/28/2013
61
62
31
1/28/2013
Taylors Theorem
If a function f ( x ) possesses derivatives of orders 1, 2, ..., ( n + 1) on an interval containing a and x then the value of f ( x ) is given by :
f ( x) =
n k =0
Remainder
where : Rn = f ( n +1) ( ) ( x a ) n +1 and is between a and x. ( n + 1)!
63
Error Term
To get an idea about the approximation error, we can derive an upper bound on : f ( n +1) ( ) Rn = ( x a ) n +1 ( n + 1)! for all values of between a and x.
64
32
1/28/2013
66
33