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

xrnew  xrold
Relative error estimate :  new
100%
x r

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


Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
% Bisection Method - simple
% function f(x) = exp(-x) - x = 0 sample call: bisection(-2, 4, 0.001,500)
MATLAB code
function root = bisection(xl, xu, es, imax);
Bisection if ((exp(-xl) - xl)*(exp(-xu) - xu))>0 % if guesses do not bracket, exit
Method disp('no bracket')
return
end

for i=1:1:imax

xr=(xu+xl)/2; % compute the midpoint xr


ea = abs((xu-xl)/xl); % approx. relative error

test= (exp(-xl) - xl) * (exp(-xr) - xr); % compute f(xl)*f(xr)


• Minimize function
evaluations in the if (test < 0) xu=xr;
code. else xl=xr;
end
Why? if (test == 0) ea=0; end
if (ea < es) break; end
• Because they are
costly (takes more end
time) s=sprintf('\n Root= %f #Iterations = %d \n', xr,i); disp(s); 6

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

• Then we can write:

Lk
 error _ tolerance
xl
L0
k
 xl *  es
2
k L0  L0 
2   k  log 2  
xl *  es  xl *  es 
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.
**here 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
detect when one of the bounds is
stuck.

If this occurs, then the original


formula xr = (xl + xu)/2 can be used

Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
**here How to find good initial guesses?

• Start at one end of the region of interest (x a) 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

Ultimate solution:
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