Вы находитесь на странице: 1из 33

1/28/2013

ICE 203 Chemical Process Computation

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

Schedule and Contents


Week I II III IV V VI VII VIII Topic Introduction Solution of Non Linear Equation f(x)=0 Solution of Non Linear Equation f(x)=0 Solution of Linear Equation AX=B Solution of Linear Equation AX=B Curve Fitting & Interpolation Numerical Optimization MID TERM EXAM

Schedule and Contents


Week IX X XI XII XIII XVI Topic Numerical Differentiation/Integration Numerical Differentiation/Integration Solution to Ordinary Differential Equation Solution to Ordinary Differential Equation Solution to Partial Differential Equation FINAL EXAM

1/28/2013

Grading

Mid Term Exam (UTS) Final Exam (UAS) Labs+Assignments + quizes

35% 35% 30%

Outlines of the Course

Solution of nonlinear Equations Interpolation Numerical Differentiation Numerical Integration

Solution of linear Equations Least Squares curve fitting Solution of ordinary differential equations Solution of Partial differential equations

1/28/2013

Solution of Nonlinear Equations


Some simple equations can be solved analytically:

x2 + 4x + 3 = 0 Analytic solution roots = 4 4 2 4 (1 )( 3 ) 2 (1 )

x = 1 and

x = 3

Many other equations have no analytical solution: 9 2

2x

+ 5 = 0 No analytic x = ex
7

solution

Methods for Solving Nonlinear Equations


o Bracketing Method : Bisection and False Position Method o Open Method : Fixed Point, Newton Raphson and Secant Method

1/28/2013

Solution of Systems of Linear Equations


x1 + x2 = 3 x1 + 2 x2 = 5 We can solve it as : x1 = 3 x2 , 3 x2 + 2 x2 = 5 x2 = 2, x1 = 3 2 = 1 What to do if we have 1000 equations in 1000 unknowns.
9

Cramers Rule is Not Practical


Cramer' s Rule can be used to solve the system : 3 5 x1 = 1 1 1 2 = 1, 1 2 1 1 x2 = 1 1 3 5 =2 1 2

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

Methods for Solving Systems of Linear Equations


o Naive Gaussian Elimination o Gaussian Elimination with Scaled Partial Pivoting o Algorithm for Tri-diagonal Equations

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

Methods for Curve Fitting


o Least Squares
o Linear Regression o Nonlinear Least Squares Problems

o Interpolation
o Newton Polynomial Interpolation o Lagrange Interpolation

14

1/28/2013

Solution of Ordinary Differential Equations


A solution to the differential equation : &&(t ) + 3x(t ) + 3 x(t ) = 0 & x & x (0) = 1; x(0) = 0 is a function x(t) that satisfies the equations. * Analytical solutions are available for special cases only.
15

Solution of Partial Differential Equations


Partial Differential Equations are more difficult to solve than ordinary differential equations:

2u
2

x t u (0, t ) = u (1, t ) = 0, u ( x,0) = sin(x)

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

Numerical Method & Mathematical Modeling

1/28/2013

Numerical Methods - Definitions

Numerical Methods

10

1/28/2013

Analytical vs. Numerical methods

Analytical vs. Numerical methods

11

1/28/2013

Reasons to study numerical Analysis


Powerful problem solving techniques and can be used to handle large systems of equations It enables you to intelligently use the commercial software packages as well as designing your own algorithm. Numerical Methods are efficient vehicles in learning to use computers It Reinforce your understanding of mathematics; where it reduces higher mathematics to basic arithmetic operation.

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

Typical characteristics of Math. model


It describes a natural process or system in mathematical way It represents the idealization and simplification of reality. It yields reproducible results, and can be used for predictive purpose.

13

1/28/2013

Example Simple Process Model


Total Mass Balance

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

h(ti +1 ) h(ti ) 1 = [ K h(ti )] ti +1 ti

1 h(ti +1 ) = h(ti ) + [ ( K h(ti ))](ti +1 ti )

New Value

Old Value

Step Size

Comparison between Analytical vs. Numerical Solution

15

1/28/2013

Pre-computer era

computer era

Approximations and Errors

16

1/28/2013

Approximations and Errors


The major advantage of numerical analysis is that a numerical answer can be obtained even when a problem has no analytical solution. Although the numerical technique yielded close estimates to the exact analytical solutions, there are errors because the numerical methods involve approximations.

Approximations and Round-Off Errors


For many engineering problems, we cannot obtain analytical solutions. Numerical methods yield approximate results, results that are close to the exact analytical solution.
Only rarely given data are exact, since they originate from measurements. Therefore there is probably error in the input information. Algorithm itself usually introduces errors as well, e.g., unavoidable round-offs, etc The output information will then contain error from both of these sources.

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

Accuracy and Precision


Accuracy refers to how closely a computed or measured value agrees with the true value. Precision refers to how closely individual computed or measured values agree with each other. Bias refers to systematic deviation of values from the true value.

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

a = Approximat e percent relative error =

21

1/28/2013

Approximate Error
In many numerical methods a present approximation is calculated using previous approximation:

a =

present approximation previous approximation 100 (%) present approximation

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%

Using one term: Using two terms:


e 0.5 = 1 + 0.5 = 1.5

e 0.5 = 1

t =

1.648721 1.0 100% = 39.3 1.648721

t =

1.648721 1.5 100% = 9.02% 1.648721

a =

1.5 1.0 100% = 33.3% 1.5

Using three terms:


e 0.5 = 1 + 0.5 + 0.52 = 1.625 2!

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

Results 1.0 1.5 1.625 1.645833333 1.648437500 1.648697917

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) ?

Can we use the definition to compute sin(0.6)? Is this a practical way?

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!

If the series converge, we can write : f ( x) =

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 ,

Zero- order approx. (n=0)

Et = 0.2 1.2 = -1.0


First- order approx. (n=1)

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

Taylor Series - Example

f(xi+1)= f(1) = 0.2 exact solution f(xi+1)=1.2

f ( x i +1 ) = f ( x i )

f(xi+1)= 0.95 f ( x ) = f ( x i ) + f ' ( x i )h i +1

25

1/28/2013

Taylor Series - Example


Second- order approximation (n=2) f(xi+1)= 0.45
f ' ' ( x i )h 2 2! f ( x i +1 ) = f ( x i ) + f ' ( x i ) h +

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!

Taylor Series - Example


Fourth-order approximation (n = 4)
f ( x i +1 ) = f ( x i ) + f ' ( x i )h +

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

Approximation using Taylor Series Expansion


The nth-order Approximation

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

Maclaurin Series Example 1


Obtain Maclaurin series expansion of f ( x ) = e x
f ( x) = e x f ' ( x) = e x f (2) ( x ) = e x f (k ) ( x) = e x ex =

f ( 0) = 1 f ' ( 0) = 1 f ( 2 ) ( 0) = 1 f ( k ) (0) = 1 for k 1 xk x2 x3 = 1+ x + + + ... k! 2! 3!

k =0

1 k ! f ( k ) ( 0) x k =

k =0

The series converges for x < .


56

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

Maclaurin Series Example 2


Obtain Maclauri n series expansion of f ( x ) = sin( x ) :

f ( x ) = sin( x ) f ' ( x ) = cos( x ) f ( 2 ) ( x ) = sin( x ) f ( 3) ( x ) = cos( x )

f ( 0) = 0 f ' ( 0) = 1 f ( 2 ) ( 0) = 0 f ( 3) (0) = 1

f ( k ) ( 0) k x 3 x5 x 7 sin( x ) = x = x + + .... k! 3! 5! 7! k =0 The series converges for x < .


58

29

1/28/2013

4 3 2 1 0 -1 -2 -3 -4 -4 x-x 3/3!+x 5/5!

sin(x)

x-x 3/3!

-3

-2

-1

59

Maclaurin Series Example 3


Obtain Maclaurin series expansion of f(x) = f ( x) = 1 1 x 1 f ' ( x) = (1 x )2 2 f ( 2) ( x ) = (1 x )3 6 f ( 3) ( x ) = (1 x )4 f ( 0) = 1 f ' ( 0) = 1 f ( 2 ) ( 0) = 2 f ( 3 ) ( 0) = 6 1 = 1 + x + x 2 + x 3 + ... 1 x 1 1 x

Maclaurin Series Expansion of : Series converges for | x | < 1

60

30

1/28/2013

Taylor Series Example 4


Obtain Taylor series expansion of f(x) = ln( x ) at ( a = 1) 1 1 2 f ( x ) = ln( x ) , f ' ( x ) = , f ( 2 ) ( x ) = 2 , f ( 3) ( x ) = 3 x x x f (1) = 0, f ' (1) = 1, f ( 2 ) (1) = 1 f ( 3) (1) = 2

1 1 Taylor Series Expansion : ( x 1) ( x 1) 2 + ( x 1) 3 ... 2 3

61

Convergence of Taylor Series


The Taylor series converges fast (few terms are needed) when x is near the point of expansion. If |x-a|=h is large then more terms are needed to get a good approximation.

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

(n+1) terms Truncated Taylor Series


f (k ) (a ) ( x a)k k! + Rn

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

Error Term - Example


How large is the error if we replaced f ( x ) = e x by the first 4 terms ( n = 3) of its Taylor series expansion at a = 0 when x = 0.2 ? f (n) ( x) = e x f ( n ) ( ) e 0.2 for n 1 f ( n +1) ( ) Rn = ( x a ) n +1 ( n + 1)! e 0.2 (0.2 )n +1 R3 8.14268E 05 Rn ( n + 1)!
65

Summary- Taylor Series


Truncation error is decreased by addition of terms to the Taylor series. If h is sufficiently small, only a few terms may be required to obtain an approximation close enough to the actual value for practical purposes.

66

33

Вам также может понравиться