Bisection Method | Source Code in C and C++| Algorithm | Pseudocode

Bisection method is an iterative method used for the solution of non-linear equations, also known as binary chopping or half-interval method.

Bisection method is based on the repeated application of the intermediate value property. It means if f(x) is continuous in the interval [a, b] and f(a) and f(b) have different sign then the equation f(x) = 0 has at least one root between x = a and x = b.

This method is most reliable and simplest iterative method for solution of nonlinear equation.

a < x < b

where, x is not of nonlinear equation.

Let f(x) = 0 be continuous between ‘a’ and ‘b’. By definition let f(a) be negative and f(b) be positive. The first approximation to the root is

 x_1 = \dfrac{a+b}{2};

Where, a and b is selected such that,

F(a)\times f(b) < 0

Now, if f(x1) = 0 the x1 is the root of f(x) otherwise the root lies between ‘a’ and x1 or x1 and ‘b’ according as f(x1) is positive or negative. Then we bisect the interval as before and continue the process until the root is found to desired accuracy.

Algorithm of Bisection Method

Step 1: Start
Step 2: Define function f(x) and error (E)
Step 3: Take two initial value for root as x1 and x2.
Step 4: Compute f(x1) and f(x2)
Step 5: If f(x_1)\times f(x_2) > 0, then x1 and x2 do not coverage and root does not lies in between x1 and x2 and go to step (10); Otherwise continue.
Step 6: If f(x1) < 0 then set a = x1 and b = x2

Else,

Set a = x2 and b = x1

Step 7: Calculate root,  x_n = \dfrac{a+b}{2} and also calculate f(xn).
Step 8: If f(xn) > 0 (i.e. positive) then,

Set b =xn

else,

set a = xn

Step 9: Repeat till step (8), until absolute value of  \dfrac{b-a}{b} is less then E, then display root.

Root = (\dfrac{a+b}{2}), go to step (10), ese to step (7).

Step 10: Stop

 

Pseudocode of Bisection Method

Input f(x), e

Repeat

Input x1 and x2 till  f(x_1) \times f(x_2) >0

Repeat

 x_0 = \dfrac{x_1 + x_2}{2}

If  f(x_1) \times f(x_2) < assign x2 = 0

Else assign x1 = x0 till |x2 – x1| > e

Display root = x0

C Source Code of Bisection Method

 

 

C++ Source code of bisection method

 

Output: Enter the value of x1 and x2

1

-3

Root is = 0.999878

 

 

Check out  other top popular Articles :

What is underpinning

Clock Signal Generator Circuit

Leave a Comment