You are on page 1of 12
KIE3005: Numerical Analysis Root finding - The Bisection Method Root finding : Bisection Method = The Bisection Method is one of the so-called “bracketing” methods for finding roots of f(x) = 0 * Like all bracketing methods, an essential “| {——| starting point is knowing two values of x at which the function has opposite sign fe) - Call the lower bound x; a3 — Call the upper bound x, = Because the function changes sign in the interval [x)x,], there MUST be a root in between a + There might be more than one however Root finding : Bisection Method = The root lies in an interval where the sign of f(x) changes = Different Sign: — Bracket contains root = Same Sign: — Bracket doesn't contain root Root finding : Bisection Method = The choice of the initial guesses for x, x, is up to us — This means we need to know something about where we expect a root to be 1 = Once we have a pair of brackets, we make ° | {| a guess for the root as the midpoint of the as interval x +%, 4 x= 2 = If f(x,) = 0, we have found the root. = Very unlikely to estimate the root first time asl — We need to “iterate” on this process x Root finding : Bisection Method To do the new iteration, we need to “choose” a new interval — This means replacing either x, or x, with x, and finding the midpoint of the new interval How do we choose a new interval? q — Itis based on the function values at x, and x, — (We could use function values at x, and x, instead — logic slightly different, result the same) = If f(x) and /(x,) have the same sign: Ix F@)>0 — The root must lie between x, and x, as, — We set the “new’ x, . Root finding : Bisection Method = If f(x) and f(x,) have different signs: L(%)*FH,) <0 — The root must lie between x, and x, — We set the “new" x, = x, = Regardless of which limit we change, make the next guess for the root equal to the midpoint of the new interval x, +x, x, =o 2 = Continue iterating until f(x,) is close enough to zero 6 = Psuedocode (or “Algorithm”) for Bisection — Assume we have the function AND values for the brackets, x, and x, 1. Calculate the midpoint of [x, , x,] 2. Calculate /(x,) and f(x) 3. Check subinterval for root, f(x) x f(x,) Reset interval bounds 4. Repeat Step 1 to 3, if f(x,) is not close enough to zero Pre-compute fil=f(x) (just once) Then iterate on Steps 1-3 if /(x,) is not close enough to zero 1. Calc. midpoint x,=0.5x(x,+x,) 2. Calculate f(x) far=f(x,) 3. Check subinterval for root and reset interval bounds IF fil * fer > 0 x, becomes the lower limit (i.e. x;= x,) Al = far ELSE x, becomes the upper limit (i.e. x, x,) END Root finding : Bisection Method al = f (&) fil =f (x), fer = (a big number) WHILE |f(x,)| > precision WHILE [fel > precision x, = 0.5% (x; + x,) x, = 0.5%(x,+x,) fer =S,) for=fte,) IF fel x far > 0 IF fel far > 0 x, becomes the lower limit (i.e. x)= x,) "2%, fol = fer Axl = far ELSE ELSE x, becomes the upper limit (i.e. x, = x,) x, =%, END END END END 10 Root finding : Bisection Method We will code Bisection in the workshops Some important points to note: = You must “bracket” the root — Else Bisection cannot choose which subinterval to use next « Bisection is guaranteed to find a root — If there is more than one root, which you find is down to luck «In testing for convergence, you MUST use abs( /(x,)) — If G,)is negative, it will be less than any (small) precision, but not close to the root END

You might also like