Komputasi Tk Kuliah 1 Genap1213
-
Upload
ferdian-tjioe -
Category
Documents
-
view
58 -
download
10
Transcript of Komputasi Tk Kuliah 1 Genap1213
1/28/2013
1
ICE 203
Chemical Process Computation
Department of Chemical EngineeringFaculty of Industrial TechnologyParahyangan 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
2
Schedule and ContentsWeek Topic
I Introduction
II Solution of Non Linear Equation f(x)=0
III Solution of Non Linear Equation f(x)=0
IV Solution of Linear Equation AX=B
V Solution of Linear Equation AX=B
VI Curve Fitting & Interpolation
VII Numerical Optimization
VIII MID TERM EXAM
Schedule and ContentsWeek Topic
IX Numerical Differentiation/Integration
X Numerical Differentiation/Integration
XI Solution to Ordinary Differential Equation
XII Solution to Ordinary Differential Equation
XIII Solution to Partial Differential Equation
XVI FINAL EXAM
1/28/2013
3
5
Grading
Mid Term Exam (UTS) 35%
Final Exam (UAS) 35%
Labs+Assignments + quizes 30%
6
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
4
7
Solution of Nonlinear Equations
• Some simple equations can be solved analytically:
• Many other equations have no analytical solution:
31
)1(2
)3)(1(444solution Analytic
034
2
2
−=−=
−±−=
=++
xandx
roots
xx
solution analytic No052 29
=
=+−− x
ex
xx
8
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
5
9
Solution of Systems of Linear
Equations
unknowns. 1000in equations 1000
have weif do What to
123,2
523,3
:asit solvecan We
52
3
12
2221
21
21
=−==⇒
=+−−=
=+
=+
xx
xxxx
xx
xx
10
Cramer’s Rule is Not Practical
this.compute toyears 10 than more needscomputer super A
needed. are tionsmultiplica102.3 system, 30by 30 a solve To
tions.multiplica
1)N!1)(N(N need weunknowns, N with equations N solve To
problems. largefor practicalnot is Rule sCramer'But
2
21
11
51
31
,1
21
11
25
13
:system thesolve toused becan Rule sCramer'
20
35
21
×
−+
==== xx
1/28/2013
6
11
Methods for Solving Systems of Linear
Equations
o Naive Gaussian Elimination
o Gaussian Elimination with Scaled Partial
Pivoting
o Algorithm for Tri-diagonal Equations
12
Curve Fitting
• Given a set of data:
• 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.
x 0 1 2
y 0.5 10.3 21.3
1/28/2013
7
13
Interpolation
• Given a set of data:
• Find a polynomial P(x) whose graph passes
through all tabulated points.
xi 0 1 2
yi 0.5 10.3 15.3
tablein the is)( iii xifxPy =
14
Methods for Curve Fitting
o Least Squares
o Linear Regression
o Nonlinear Least Squares Problems
o Interpolation
o Newton Polynomial Interpolation
o Lagrange Interpolation
1/28/2013
8
15
Solution of Ordinary Differential
Equations
only. cases special
for available are solutions Analytical *
equations. thesatisfies that function a is
0)0(;1)0(
0)(3)(3)(
:equation aldifferenti theosolution tA
x(t)
xx
txtxtx
==
=++
&
&&&
16
Solution of Partial Differential Equations
Partial Differential Equations are more difficult
to solve than ordinary differential equations:
)sin()0,(,0),1(),0(
022
2
2
2
xxututu
t
u
x
u
π===
=+∂
∂+
∂
∂
1/28/2013
9
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
10
Numerical Methods - Definitions
Numerical Methods
1/28/2013
11
Analytical vs. Numerical methods
Analytical vs. Numerical methods
1/28/2013
12
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
1/28/2013
13
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.
1/28/2013
14
Example Simple Process Model
qf
q=kh
h
k
qK
k
AKth
dt
tdh
tkhqdt
tdhA
tqqdt
tAhd
tqqdt
tmd
f
f
f
f
===+
−=
−=
−=
,;)()(
)()(
)]([)]([
)]([)]([
ττ
ρρ
ρ
Total Mass Balance
qf : inlet volumetric flowrate
q : outlet volumetric flowrate
h(0)=0
Analytical solution
Solving the differential equations, it gives
h(t
)
t
hs=K
1/28/2013
15
Numerical solution
)]([1)(
thKdt
tdh−=
τ)]([
1)()(
1
1i
ii
ii thKtt
thth−=
−
−
+
+
τ
)))](((1
[)()( 11 iiiii ttthKthth −−+= ++τ
New Value Old Value Step Size
Comparison between Analytical vs. Numerical Solution
t
h
1/28/2013
16
Pre-computer era computer era
Approximations and Errors
1/28/2013
17
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”.
Chapter 3 34
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?”
1/28/2013
18
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
Truncation errors Round-off errors
Errors
Result when approximations
are used to represent
exact mathematical
procedure.
Result when numbers having
limited significant figures are
used to represent exact
numbers.
1/28/2013
19
Round-off Errors
• Numbers such as π, e, or 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
7
Truncation Errors
• Truncation errors are those that result using
approximation in place of an exact mathematical
procedure.
( ) ( )1
1
i i
i i
V t V tdv v
dt t t t
+
+
−∆≈ =
∆ −
1/28/2013
20
True Error
tε
True error (Et) or Exact value of error
= true value – approximated value
�True error (Et)
�True percent relative error ( )
(%)100
(%)100
×−
=
×==
valuetrue
valueedapproximatvaluetrue
valueTrue
errorTrueerrorrelativepercentTrue tε
Example
1/28/2013
21
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:
(%)100×==ionapproximat
erroreApproximaterrorrelativepercenteApproximataε
1/28/2013
22
Approximate Error
• In many numerical methods a present approximation is
calculated using previous approximation:
aε tε
(%)100×−
=ionapproximatpresent
ionapproximatpreviousionapproximatpresentaε
Note:
- The sign of or 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):
sa εε <
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:
%)105.0( 2 n
s
−×=ε
1/28/2013
23
Example
The exponential function can be computed using Maclaurin
series as follows:
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
2 3
12! 3! !
nx x x x
e xn
= + + + + +L
( )2 30.5 10 % 0.05%s
ε −= × =
� Using one term:
� Using two terms:
� Using three terms:
0.5 1.648721 1.01 100% 39.3
1.648721t
e ε−
= = =
εεεεa%εεεεt%ResultsTerms
---39.31.01
33.39.021.52
7.691.441.6253
1.270.1751.6458333334
0.1580.01721.6484375005
0.01580.001421.6486979176
0.5 1.648721 1.5 1.5 1.01 0.5 1.5 100% 9.02% 100% 33.3%
1.648721 1.5t ae ε ε
− −= + = = = = =
20.5 0.5 1.648721 1.625 1.625 1.0
1 0.5 1.625 100% 1.44% 100% 7.69%2! 1.648721 1.625
t ae ε ε− −
= + + = = = = =
1/28/2013
24
Taylor Series
48
Motivation
• We can easily compute expressions like:
?)6.0sin(,4.1 computeyou do HowBut,
)4(2
103 2
+
×
x
way?practicala thisIs
sin(0.6)? compute to
definition theuse weCan
0.6
ab
1/28/2013
25
49
Taylor Series
∑∞0
)(
0
)(
3)3(
2)2(
'
)()( !
1 )(
: writecan weconverge, series theIf
)()( !
1
...)(!3
)()(
!2
)()()()(
:about )( of expansion seriesTaylor The
=
∞
=
−=
−=
+−+−+−+
∑
k
kk
k
kk
axafk
xf
axafk
SeriesTaylor
or
axaf
axaf
axafaf
axf
Taylor Series - Example
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 function’s value at xi+1 =1.
Solution� f(xi)= f(0)= 1.2 , f(xi+1)= f(1) = 0.2 ………exact solution
• Zero- order approx. (n=0) ���� f(xi+1)=1.2
Et = 0.2 – 1.2 = -1.0
• First- order approx. (n=1) � f(xi+1)= 0.95
f(x)= -0.4x3 – 0.45x2 – x – 0.25, f ’(0)= -0.25f( xi+1)= 1.2- 0.25h = 0.95Et = 0.2 - 0.95 = -0.75
)()(1 ii
xfxf =+
hxfxfxf iii)()()(
'
1+=
+
50
1/28/2013
26
Taylor Series - Example
• Second- order approximation (n=2) � f(xi+1)= 0.45
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( xi+1)= 1.2 - 0.25h - 0.5 h2 – 0.15h3 = 0.3
Et = 0.2 – 0.3 = -0.1
!2
)('')()()(
2'
1
hxfhxfxfxf i
iii++=
+
!3
)(
!2
)('')()()(
3(3)2'
1
hxfhxfhxfxfxf ii
iii+++=
+
51
Taylor Series - Example
• Fourth-order approximation (n = 4) � f(xi+1)= 0.2
f( xi+1)= 1.2 - 0.25h - 0.5 h2 – 0.15h3 – 0.1h 4= 0.2
Et = 0.2 – 0.2 = 0
The remainder term (R4) = 0
because the fifth derivative of the fourth-order polynomial is
zero.
!4
)(
!3
)(
!2
)('')()()(
4)4(3)3(2'
1
hxfhxfhxfhxfxfxf iii
iii++++=
+
5)5(
4!5
)(h
fR
ξ=
52
1/28/2013
27
53
Approximation using Taylor Series Expansion
The nth-order Approximation
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
1/28/2013
28
55
Maclaurin Series
�Maclaurin series is a special case of Taylor series with the center of expansion a = 0.
∑∞0
)(
3)3(
2)2(
'
)0( !
1 )(
: writecan weconverge, series theIf
...!3
)0(
!2
)0()0()0(
:)( of expansion series n MaclauriThe
=
=
++++
k
kkxf
kxf
xf
xf
xff
xf
56
Maclaurin Series – Example 1
∞.xfor converges series The
...!3!2
1!
)0(!
1
11)0()(
1)0()(
1)0(')('
1)0()(
32∞0
∞0
)(
)()(
)2()2(
∑∑<
++++===
≥==
==
==
==
==
xxx
k
xxf
ke
kforfexf
fexf
fexf
fexf
k
k
k
kkx
kxk
x
x
x
xexf =)( of expansion series n MaclauriObtain
1/28/2013
29
57
Taylor SeriesExample 1
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 10
0.5
1
1.5
2
2.5
3
1
1+x
1+x+0.5x2
exp(x)
58
Maclaurin Series – Example 2
∞.xfor converges series The
....!7!5!3!
)0()sin(
1)0()cos()(
0)0()sin()(
1)0(')cos()('
0)0()sin()(
753∞0
)(
)3()3(
)2()2(
∑<
+−+−==
−=−=
=−=
==
==
=
xxxxx
k
fx
fxxf
fxxf
fxxf
fxxf
k
kk
: )sin()( of expansion series n MaclauriObtain xxf =
1/28/2013
30
59
-4 -3 -2 -1 0 1 2 3 4-4
-3
-2
-1
0
1
2
3
4
x
x-x3/3!
x-x3/3!+x5/5!
sin(x)
60
Maclaurin Series – Example 3
( )
( )
( )
1 ||for converges Series
...xxx1x1
1 :ofExpansion Series Maclaurin
6)0(1
6)(
2)0(1
2)(
1)0('1
1)('
1)0(1
1)(
of expansion series n MaclauriObtain
32
)3(
4
)3(
)2(
3
)2(
2
<
++++=−
=−
=
=−
=
=−
=
=−
=
−=
x
fx
xf
fx
xf
fx
xf
fx
xf
x1
1f(x)
1/28/2013
31
61
Taylor Series – Example 4
...)1(3
1)1(
2
1)1( :Expansion SeriesTaylor
2)1(1)1(,1)1(',0)1(
2)(,
1)(,
1)(',)ln()(
)1(at )ln( of expansion seriesTaylor Obtain
32
)3()2(
3
)3(
2
)2(
−−+−−−
=−===
=−
===
==
xxx
ffff
xxf
xxf
xxfxxf
axf(x)
62
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.
1/28/2013
32
63
Taylor’s Theorem
. and between is)()!1(
)(
:where
)(!
)( )(
:by given is )( of value the then and containing interval an on
1)( ..., 2, 1, orders of sderivative possesses )( functiona If
1)1(
0
)(∑
xaandaxn
fR
Raxk
afxf
xfxa
nxf
nn
n
n
n
k
kk
ξξ +
+
=
−+
=
+−=
+
(n+1) terms Truncated
Taylor Series
Remainder
64
Error Term
. and between allfor
)()!1(
)(
:on boundupper an derive can we
error, ionapproximat about theidea anget To
1)1(
xaofvalues
axn
fR
nn
n
ξ
ξ ++
−+
=
1/28/2013
33
65
Error Term - Example
( ) 0514268.82.0)!1(
)()!1(
)(
1≥≤)()(
31
2.0
1)1(
2.0)()(
−≤⇒+
≤
−+
=
=
+
++
ERn
eR
axn
fR
nforefexf
nn
nn
n
nxn
ξ
ξ
?2.00at
expansion seriesTaylor its of3)( terms4first the
by )( replaced weiferror theis largeHow
==
=
=
xwhena
n
exfx
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