Roots of Equations Bracketing Methods: Credit: Prof. Lale Yurttas, Chemical Eng., Texas A&M University

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 11

~ Roots of Equations ~

Bracketing Methods
Chapter 5

Credit: Prof. Lale Yurttas, Chemical Eng., Texas A&M University 1


Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Roots of Equations

• Easy
2
2  b  b  4ac
ax  bx  c  0  x 
2a

• But, not easy


ax 5  bx 4  cx 3  dx 2  ex  f  0  x?

• How about these?


sin x  x  0  x?
cos(10 x)  sin(3 x)  0  x  ?
2
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Graphical Approach
• Make a plot of the Using MATLAB, plot f(x)=sin(10x)+cos(3x)
function f(x) and
observe where it
crosses the x-axis,
i.e. f(x) = 0

• Not very practical


but can be used to
obtain rough
estimates for roots
Two distinct
• These estimates can roots between
be used as initial
x= 4.2 and 4.3
guesses for
numerical methods need to be careful
that we’ll study here.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Bracketing:
exceptions

Odd and even


number of roots

4
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Bisection Method

xu  xl
Relative error estimate:  100%
Min{xl ; xu }

Termination criteria:  < tol OR Max.Iteration is reached


Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
% Bisection Method
% function is available in another file e.g. func1.m
MATLAB code % A sample call: bisection2(@func1, -2, 4, 0.001, 500)

function root = bisection(fx, xl, xu, es, imax);


Bisection
Method if fx(xl)*fx(xu) > 0 % if guesses do not bracket
disp('no bracket')
return
end

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
if test == 0
Why?
ea=0;
end
• Because they are if ea < es
costly (takes more break;
end
time) 6

endCopyright © 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

• Then we can write:

Lk
 error _ tolerance where xr  Min{ xl , xu }
xr
L0
k
 xr *  tol
2

k L0  L0 
2   k  log 2 
xr *  tol  x r *  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)
• We can approximate the
solution by doing a
linear interpolation
between f(xu) and f(xl)

• Find xr such that


l(xr)=0, where l(x) is the
linear approximation of
f(x) between xl and xu

• Derive xr using similar


triangles

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+x), f(xa+2x), f(xa+3x), ........

• Continue until the sign of the result changes.


If that happens between f(xa+k*x) and f(xa+(k+1)*x)

then pick xl= xa+k*x and xu= xa+(k+1)*x

Problem:
if x is too small  search is very time consuming
if x 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.

You might also like