Transcript PPT
Bisection Method Computer Engineering Majors Authors: Autar Kaw, Jai Paul http://numericalmethods.eng.usf.edu Transforming Numerical Methods Education for STEM Undergraduates 7/12/2016 http://numericalmethods.eng.usf.edu 1 Bisection Method http://numericalmethods.eng.usf.edu Basis of Bisection Method Theorem An equation f(x)=0, where f(x) is a real continuous function, has at least one root between xl and xu if f(xl) f(xu) < 0. f(x) x xu x Figure 1 At least one root exists between the two points if the function is real, continuous, and changes sign. 3 http://numericalmethods.eng.usf.edu Basis of Bisection Method f(x) x xu x Figure 2 If function f x does not change sign between two points, roots of the equation f x 0 may still exist between the two points. 4 http://numericalmethods.eng.usf.edu Basis of Bisection Method f(x) f(x) x x xu x xu x Figure 3 If the function f x does not change sign between two points, there may not be any roots for the equation f x 0 between the two points. 5 http://numericalmethods.eng.usf.edu Basis of Bisection Method f(x) xu x x Figure 4 If the function f x changes sign between two points, more than one root for the equation f x 0 may exist between the two points. 6 http://numericalmethods.eng.usf.edu Algorithm for Bisection Method 7 http://numericalmethods.eng.usf.edu Step 1 Choose x and xu as two guesses for the root such that f(x) f(xu) < 0, or in other words, f(x) changes sign between x and xu. This was demonstrated in Figure 1. f(x) x xu x Figure 1 8 http://numericalmethods.eng.usf.edu Step 2 Estimate the root, xm of the equation f (x) = 0 as the mid point between x and xu as f(x) x xu xm = 2 x xm xu x Figure 5 Estimate of xm 9 http://numericalmethods.eng.usf.edu Step 3 Now check the following a) If f xl f xm 0 , then the root lies between x and xm; then x = x ; xu = xm. b) If f xl f xm 0 , then the root lies between xm and xu; then x = xm; xu = xu. c) If f xl f xm 0 ; then the root is xm. Stop the algorithm if this is true. 10 http://numericalmethods.eng.usf.edu Step 4 Find the new estimate of the root x xu xm = 2 Find the absolute relative approximate error a old x new x m m x new m 100 where xmold previous estimate of root xmnew current estimate of root 11 http://numericalmethods.eng.usf.edu Step 5 Compare the absolute relative approximate error a with the pre-specified error tolerance s . Yes Go to Step 2 using new upper and lower guesses. No Stop the algorithm Is a s ? Note one should also check whether the number of iterations is more than the maximum number of iterations allowed. If so, one needs to terminate the algorithm and notify the user about it. 12 http://numericalmethods.eng.usf.edu Example 1 To find the inverse of a value, a, one can use the equation 1 f x a 0 x where x is the inverse of a. Use the bisection method of finding roots of equations to find the inverse of a = 2.5. Conduct three iterations to estimate the root of the above equation. Find the absolute relative approximate error at the end of each iteration and the number of significant digits at least correct at the end of each iteration. 13 http://numericalmethods.eng.usf.edu Example 1 Cont. 1.5 1.5 1 0.5 f ( x) 0 0 0.5 1 1 0 0.25 0 0.5 0.75 x 1 1 f(x) Figure 8 Graph of the function f(x). 1 f x a 0 x 14 http://numericalmethods.eng.usf.edu Example 11 Cont. Solution Entered function on given interval with initial upper and lower guesses 1.505 2 1 0 0 f ( x) f ( x) 2 f xu f 1 2.51 1 1.5 1 0.5 1 0 0.5 x x u x l 1 1.5 1.002 f(x) xu (upper guess) xl (lower guess) Figure 9 Checking that the bracket is valid. 15 x f ( x ) ax 1 0 f ( x ) 2 .5 x 1 0 Let us assume xl 0, xu 1 f xl f 0 2.50 1 1 3 4 0 Check if the function changes sign between xl and xu . 1 f ( x) 3.5 a f xl f xu f 0 f 1 11.5 0 There is at least one root between the brackets. http://numericalmethods.eng.usf.edu Example 1 Cont. 1.505 Iteration 1 The estimate of the root is 2 xl xu 0 1 xm 0.5 2 2 f xm f 0.5 2.50.5 1 0.25 f xl f xm f 0 f 0.5 10.25 0 1 0 f ( x) 0 f ( x) f ( x) 1 f ( x) 2 3 3.5 4 1 0.5 1 0 0.5 1 x x u x l x r f(x) xu (upper guess) xl (lower guess) new guess Figure 10 Graph of the estimated root after Iteration 1. 16 1.5 1.002 The root is bracketed between and xm . The lower and upper limits of the new bracket are xl xl 0, xu 0.5 The absolute relative approximate error a cannot be calculated as we do not have a previous approximation. http://numericalmethods.eng.usf.edu Example 1 Cont. 1.505 Iteration 2 The estimate of the root is 2 xl xu 0 0.5 xm 0.25 2 2 1 0 f ( x) 0 f xm f 0.25 2.50.25 1 0.375 f ( x) f ( x) 1 f ( x) 2 f xm f xu f 0.25 f 0.5 0.3750.25 0 3 3.5 4 1 0.5 1 0 0.5 x x u x l x r 1 1.5 1.002 f(x) xu (upper guess) xl (lower guess) new guess Figure 11 Graph of the estimated root after Iteration 2. 17 The root is bracketed between xm and xu . The lower and upper limits of the new bracket are xl 0.25, x u 0.5 http://numericalmethods.eng.usf.edu Example 1 Cont. The absolute relative approximate error a at the end of Iteration 2 is xmnew xmold a 100 new xm 0.25 0.5 100 0.25 100% None of the significant digits are at least correct in the estimated root of x 0.25 m as the absolute relative approximate error is greater than 5%. 18 http://numericalmethods.eng.usf.edu Example 1 Cont. 1.505 Iteration 3 The estimate of the root is 2 1 xl xu 0.25 0.5 0.375 2 2 f xm f 0.375 2.50.375 1 0.0625 0 f ( x) xm 0 f ( x) f ( x) f ( x) 1 2 f xm f xu f 0.375 f 0.5 3 3.5 4 1 0.5 1 0 0.5 1 x x u x l x r f(x) xu (upper guess) xl (lower guess) new guess Figure 12 Graph of the estimated root after Iteration 3. 1.5 1.002 0.06250.25 0 The root is bracketed between xm and xu . The lower and upper limits of the new bracket are xl 0.25, xu 0.5 19 http://numericalmethods.eng.usf.edu Example 1 Cont. The absolute relative approximate error a at the end of Iteration 3 is xmnew xmold a 100 new xm 0.375 0.25 100 0.375 33.333% Still none of the significant digits are at least correct in the estimated root of the equation as the absolute relative approximate error is greater than 5%. Seven more iterations were conducted and these iterations are shown in the table below. 20 http://numericalmethods.eng.usf.edu Example 1 Cont. Table 1 Root of f x 0 as function of number of iterations for bisection method. 21 Iteration xl xu xm a % f xm 1 2 3 4 5 6 7 8 9 10 0 0 0.25 0.375 0.375 0.375 0.39063 0.39844 0.39844 0.39844 1 0.5 0.5 0.5 0.4375 0.40625 0.40625 0.40625 0.40234 0.40039 0.5 0.25 0.375 0.4375 0.40625 0.39063 0.39844 0.40234 0.40039 0.39941 ---------100 33.33 14.2857 7.6923 4.00 1.9608 0.97087 0.48780 0.24450 0.25 −0.375 −0.0625 0.09375 0.01563 −0.02344 −3.90625×10-3 5.8594×10-3 9.7656×10-4 −1.4648×10-3 http://numericalmethods.eng.usf.edu Advantages 22 Always convergent The root bracket gets halved with each iteration - guaranteed. http://numericalmethods.eng.usf.edu Drawbacks 23 Slow convergence If one of the initial guesses is close to the root, the convergence is slower http://numericalmethods.eng.usf.edu Drawbacks (continued) If a function f(x) is such that it just touches the x-axis it will be unable to find the lower and upper guesses. f(x) f x x 2 x 24 http://numericalmethods.eng.usf.edu Drawbacks (continued) Function changes sign but root does not exist f(x) 1 f x x x 25 http://numericalmethods.eng.usf.edu Additional Resources For all resources on this topic such as digital audiovisual lectures, primers, textbook chapters, multiple-choice tests, worksheets in MATLAB, MATHEMATICA, MathCad and MAPLE, blogs, related physical problems, please visit http://numericalmethods.eng.usf.edu/topics/bisection_ method.html THE END http://numericalmethods.eng.usf.edu