Root Finding: Close Methods Bisection and False Position Dr. Marco A. Arocha Aug, 2014 1
Roots Given function f(x), we seek x values for which f(x)=0 Solution x is the root of the equation or zero of the function f(x) Problem is known as root finding or zero finding 2
Number of Roots Nonlinear equations can have any number of solutions: exp(x) + 1 = 0 exp( x) x = 0 x 2 4 sin(x) = 0 x 3 + 6x 2 + 11x 6 = 0 sin(x) = 0 has no solution has one solution has two solutions has three solutions has infinitely many solutions 3
Roots Root solving involves finding the values of x which satisfy relationships such as: ax 4 + bx 3 + cx 2 dx + c = 0 tan ax x 2 = 0 For values of x other than the roots, the above equations will not be satisfied and can be better expressed as: ax 4 + bx 3 + cx 2 dx + c = f(x) tan ax x 2 = g(x) Expressed as above allow us to graph them, e.g., f(x) vs x ; g(x) vs x Finding the roots of these equations is equivalent to finding the values of x for which f(x) and g(x) are zero 4
Graphical Methods A simple method for obtaining the estimate of the root of the equation f(x)=0 is to make a plot of the function as f(x) vs x and observe where it crosses the x-axis. Graphing the function can also indicate where roots may be and where some root-finding methods may fail: who is doing this one? a) Same sign, no roots b) Different sign, one root c) Same sign, two roots d) Different sign, three roots 5
Graphical methods Some difficult cases: Multiple roots that occurs when the function is tangential to the x axis. For this case, although the end points are of opposite signs, there are an even number of axis intersections for the interval. Discontinuous function where end points of opposite sign bracket an even number of roots. Special strategies are required for determining the roots for these cases. 6
GRAPHICAL METHODS Graphical techniques: Alone are of limited practical value because they are not precise. Are utilized to obtain rough estimates of roots. These estimates are employed as starting guesses for numerical methods. Are important tools for understanding the properties of the functions and anticipating the pitfalls of the numerical methods. 7
If you are asked to hand in a graph of a function in search of a root, what graph would you finally turn in? 8
Bracketing methods They are also called close methods as opposed to other methods called open methods. They exploit the fact that a function typically changes sign in the vicinity of a root. The method requires two initial guesses in each side of the root. The particular methods employ different strategies to systematically reduce the width of the bracket and, hence, home in on the correct answer. Close methods are generally slower than open methods but more robust. 9
Bisection The bisection method is a search method in which the interval is progressively divided in half. If a function changes sign over an interval, the function value at the midpoint is evaluated. The location of the root is then determined as lying within the subinterval where the sign change occurs. The absolute error is reduced by a factor of 2 for each iteration. c root 10
first iteration second iteration third iteration fourth iteration 11
Algorithm: Step 1: Choose lower a and upper b guesses for the root such that the function changes sign over the interval. This can me checked by ensuring that f(a)f(b)<0 Step 2: An estimate of the root c is determined by c=(a+b)/2 Step 3: Determine in which subinterval the root lies: (a) if f(a)f(c)<0, then b=c; return to Step 2 (b) if f(a)f(c)>0, then a=c; return to Step 2 (c) if f(a)f(c)=0, then error=0, and c is the root, Stop computation Step 4: Repeat Step 2 to 3 until a Stopping criterium is reached 12
Bisection Method, Stop Criteria: We can use one or more of the following criteria for the iteration process: 1. Interval small enough, i.e., (b-a) ϵ, where ϵ is a very small number. ϵ is an approximate error where a is the root lower bound and b is the root upper bound of the present iteration. The absolute value is used because we are usually concerned with the magnitude of ϵ rather than with its sign. 2. f(c) very small,i.e., f(c) ϵ; where c is the middle point and the new root estimate 3. Max number of iterations reached 4. Any number or combination of the criteria listed in (1), (2), and (3) An approximate percent relative error ε a can also be calculated: ε a = c new C old 100% C new where c new is the root for the present iteration and c old is the root from the previous iteration. The absolute value is used because we are usually concerned with the magnitude of ε a rather than with its sign. 13
BISECTION PSEUDOCODE INPUT a, b, tol, imax iter = 0 DO c = (a + b) / 2 iter = iter + 1 error = ABS(b-a) IF (f(a) * f(c))<0 THEN b = c ELSEIF (f(a) * f(c))>0 THEN a = c ELSE error = 0 END IF WHILE error>tol AND iter imax Result = c 14
false position method An alternative method to bisection, sometimes faster. Exploits a graphical strategy, join f(a) and f(b) by a straight line. The intersection of this line with the x axis represents an improved estimate of the root. The fact that the replacement of the curve by a straight line gives a false position of the root is the origin of the name, method of false position, or in Latin, regula falsi. It is also called the linear interpolation method. 15
false position method Derive the method s formula by using similar triangles. The intersection of the straight line with the x axis c can be estimated as f b 0 b c = (f a 0) c a which can be solved for c c = b f(b) (a b) f(a) f(b) 16
false position method The value of c so computed then replaces whichever of the two initial guesses, a or b, yields a function value with the same sign as f(c). By this way, the values of a and b always bracket the true root. The process is repeated until the root is estimated. The algorithm is similar to the one for bisection with the exception for the c eq. The difference is that the root is approached from only one side of the values bracketing the root, as you can see in the next slide. 17
pitfalls for some cases false-position method may show slow convergence 18
FALSE POSITION Method, Stop Criteria: We can use one or more of the following criteria for the iteration process: 1. f(c) very small,i.e., f(c) ϵ 2. Max number of iterations reached 3. Any number or combination of the criteria listed in (1), (2), and (3) ONE COMPLICATION: As this method approaches the root from one side of the interval (b-a), either from the left or the right of the interval, the criterion interval small enough, i.e., (b-a) ϵ, can t be used for this method. For instances, you can see this problem in the Excel program. 19
quick comparison Bisection New estimate of the root: Stop criteria: c = (a + b) 2 error = b a tolerance False Position New estimate of the root c = b f(b) Stop criteria f(c) tolerance (a b) f(a) f(b) 20