Roots of Equations Bracketing Methods: Credit: Prof. Lale Yurttas, Chemical Eng., Texas A&M University
Roots of Equations Bracketing Methods: Credit: Prof. Lale Yurttas, Chemical Eng., Texas A&M University
Bracketing Methods
Chapter 5
• Easy
b b 2
4ac
ax bx c 0 x
2
2a
4
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Bisection Method
xu xl
Relative error estimate: e 100%
Min{xl ; xu }
for i=1:1:imax
xr=(xu+xl)/2
ea = abs((xu-xl)/xl);
test= fx(xl)*fx(xr);
if test < 0
• Minimize function xu=xr;
end
evaluations in the if test > 0
code. xl=xr;
end
Why? if test == 0
ea=0;
end
• Because they are if ea < es
costly (takes more break;
end
time) 6
end Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
How Many Iterations will It Take?
• Length of the first Interval Lo= xu- xl
• After 1 iteration L1=Lo/2
• After 2 iterations L2=Lo/4
….. …..
• After k iterations Lk=Lo/2k
Lk
error _ tolerance wher e xr Min{ xl , xu }
xr
L0
k
xr * e tol
2
L0 L0
2
k
k log 2
xr * e tol x r * e tol
7
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Bisection Method
Pros Cons
• Easy • Slow
• Always finds a root • Need to find initial
• Number of iterations guesses for xl and xu
required to attain an • No account is taken
absolute error can be of the fact that if f(xl)
computed a priori. is closer to zero, it is
likely that root is
closer to xl .
8
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
The False-Position Method (Regula-Falsi)
xl f u xu f l
xr
fu fl
9
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
The False-Position Method
Works well, but not always!
Here is a pitfall
Modified False-Position
One way to mitigate the “one-sided”
nature of the false position (i.e. the
pitfall case) is to have the algorithm
pick the smallest bracket (between
the Bisection Method & this one)
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
How to find good initial guesses?
• Start at one end of the region of interest (xa) and evaluate
f(xa), f(xa+Dx), f(xa+2Dx), f(xa+3Dx), ........
Problem:
if Dx is too small search is very time consuming
if Dx is too large could jump over two closely spaced roots
Suggestions:
• Generate random x values and evaluate f(x) each time until you find two values that
satisfy f(x1)*f(x2) < 0
• Know the application and plot the function to see the location of the roots, and pick xl
and xu accordingly to start the iterations.
11
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.