Lecture 3
Lecture 3
Lecture 3
Root finding
Optimization
CHBE 230 - Lecture 3
Fixed-point iteration
Iterative scheme based on successive substitutions
Basic principle
f (x) = 0 rewritten as x = g(x) ) xi+1 = g(xi )
convergence to 2
x2 x1 G G x1 x2
CHBE 230 - Lecture 3
Ei y=x
y=g(x)
Ei+1
Ei
Root!
xi xi+1
CHBE 230 - Lecture 3
Newton-Raphson method
Better scheme than fixed-point iteration, although
convergence is not guaranteed either
Fundamental to many numerical schemes as
linearization is almost the only tool we have to solve
non-linear problems (a key idea of CHBE 230)
Principle: locally approximate f(x) by a straight line
using its tangent i.e. f’(x)
Equation of tangent line:
0
y f (xi ) = f (xi )(x xi )
Where does it intersect y=0
f (xi )
at xi+1 defined by: xi+1 = xi
f 0 (xi )
CHBE 230 - Lecture 3
Graphical explanation
f(x)
f(xi+1)
x
xi+1 xi
root
CHBE 230 - Lecture 3
Why?
CHBE 230 - Lecture 3
f(x)
x1 x2
x0 x
root
CHBE 230 - Lecture 3
f(x)
root root
CHBE 230 - Lecture 3
h ⇡h2
V = (3r h)
3
solid Inputs: fluid density,
solid density, sphere
liquid radius r
Questions:
1. formulate the equation for h
2. find h with the different root finding methods
CHBE 230 - Lecture 3
Solution:
1. We write “sum of the forces is equal to 0”
4 3
Fweight = ⇡r ⇢solid g
3 ✓ ◆
2
4 3 ⇡h
Fbuoyancy = ⇡r (3r h) ⇢f luid g
3 3
After some algebra, we get a 3rd order polynomial
equation in h:
3 2 3 ⇢f luid ⇢solid
h 3rh + 4r =0
⇢f luid
2. We use bisection or false position method to find the
root as this equation has a single root.
Please note that there is a solution only if ⇢f luid > ⇢solid
CHBE 230 - Lecture 3
Optimization
Common in engineering problems to find maxima or
minima of f(x). For example:
0
f(x)
Minimum:
f’(x)=0, f’’(x)>0
CHBE 230 - Lecture 3
f(x1)
f(xl)
f(x2)
f(x)
xl x2 x1 xu
f(xu) x
f(x1)
f(xl)
f(x2)
xl x1 xu,new=x1
f(x2)< f(x1) means there is at least one point (x2) in [xl,x1] at which f
falls between the f values at the two bounds.
CHBE 230 - Lecture 3
How to set c ?
Labor saving trick: set c such that
old x2 becomes new x1, or
old x1 becomes new x2
c 1-c
xl x2 x1 xu
1-c c
Eliminate
p
c1 1 −c c 5 1
=
= ) c= ' 0.618
1c 1c c 2
CHBE 230 - Lecture 3
1 5+1
ϕ= =1+c= = 1.61803398874989......
c 2
CHBE 230 - Lecture 3
c 1-c
xl x2 x1 xu
1-c c
Eliminate
We have x2,old = xl + (1 c)(xu,old xl )
Now x1,new in the interval [xl,x1,old]=[xl,xu,new]
x1,new = xl + c(xu,new xl ) = xl + c.c(xu,old xl )
2
But the golden ratio is constructed such that c = 1 c
x1,new = xl + (1 c)(xu,old xl ) = x2,old
CHBE 230 - Lecture 3
Pseudo code
Inputs: endpoints a,b; tolerance es; max number of
iterations maxit
Outputs: xmin, fmin=f(xmin), estimate error ea, number of
iterations for convergence i p
1+ 5
Initialization: i=0, xl,0=a, xu,0=b, =
2
Iterative loop: i=i+1
1. d=(φ-1)(xu,i-1-xl,i-1), x1,i=xl,i-1+d, x2,i=xu,i-1-d
2. if f(x1,i)<f(x2,i), xl,i=x2,i and xu,i=xu,i-1, xopt=x1,i
else xu,i=x1,i and xl,i=xl,i-1, xopt=x2,i
3. compute ea=100(2-φ)|(xu,i-xl,i)/xopt|
4. If ea<tol or i>=maxit, xmin=xopt, STOP
CHBE 230 - Lecture 3
xl x2 x1 xu
f(xu) x
f(x1)
f(xl)
f(x2) max( l , 1)
ea = 100
Δl Δ1 xopt
CHBE 230 - Lecture 3