Sei sulla pagina 1di 13

~ Roots of Equations ~ Bracketing Methods

1
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Roots of Equations
Easy
ax 2 bx c 0 b b 2 4ac x 2a

But, not easy


ax5 bx 4 cx 3 dx 2 ex f 0 sin x x 0 x? cos( 10 x) sin(3x) 0 x? x?

2
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Graphical Approach
Make a plot of the 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 These estimates can be used as initial guesses for numerical methods that well study here.

3
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Fig 5.2
Different cases: Odd and even number of roots

Fig 5.3
exceptions

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

Bisection Method

Relative error estimate :

xrnew xrold x
new r

100 %

Termination criteria: e < Epsilon OR Max.Iteration is reached


5
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Fig 5.10: Pseudocode to implement the Bisection Method

6
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Bisection Method
Pros Easy Always finds a root Number of iterations required to attain an absolute error can be computed a priori. How? Cons Slow Need to find initial guesses for xl and xu Multiple roots No account is taken of the fact that if f(xl) is closer to zero, it is likely that root is closer to xl .
7
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

How Many Iterations will It Take?


Length of the first Interval After 1 iteration After 2 iterations After k iterations Lo= xu-xl L1=Lo/2 L2=Lo/4 Lk=Lo/2k

If the root (solution) is close to xl then we can write

Lk desired _ relative _ error xl L0 xl * (desired _ relative _ error ) k 2 solve for k

8
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Fig 5.11 Minimize function evaluations in the code. Why? Because they are costly (takes more time)

9
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

The False-Position Method


(Regula-Falsi)
If the root is between xl and xu, then we can approximate the solution by doing a linear interpolation between the points [xl, f(xl)] and [xu, f(xu)] to find the xr value such that l(xr)=0, where l(x) is the linear approximation of f(x). Derive xr using similar triangles (Box 5.1):

Fig. 5.12

xl f u xu f l xr fu fl
10
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

The False-Position Method


Good! but be careful Here is a pitfall

Interesting!

11
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

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, the function value at the stagnant bound can be divided in half (original Bisection method). The resultant code

12
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), ........ Continue until the sign of the result changes. If that happens between f(xa+k*Dx) and f(xa+(k+1)*Dx) then pick xl= xa+k*Dx and xu= xa+(k+1)*Dx

Problem: if Dx is too small search is very time consuming if Dx is too large could miss two closely spaced roots even worse, if there is a multiple root.
partial solution: if the 1.derivative, f(.), changes sign in an interval, it suggests a local
minima/maxima and the vicinity should be examined more carefully for 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.
13
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Potrebbero piacerti anche