Bisection Method - Pseudocode

Pseudocode

The method may be written in Pseudocode as follows:

INPUT: Function f, endpoint values a, b, tolerance TOL, maximum iterations NMAX CONDITIONS: a < b, either f(a) < 0 and f(b) > 0 or f(a) > 0 and f(b) < 0 OUTPUT: value which differs from a root of f(x)=0 by less than TOL N ← 1 While NNMAX { limit iterations to prevent infinite loop c ← (a + b)/2 new midpoint If (f(c) = 0 or (ba)/2 < TOL then { solution found Output(c) Stop } NN + 1 increment step counter If sign(f(c)) = sign(f(a)) then ac else bc new interval } Output("Method failed.") max number of steps exceeded

Read more about this topic:  Bisection Method