To Find The Roots of Non-Linear Equation Using Bisection Method
To Find The Roots of Non-Linear Equation Using Bisection Method
EXPERIMENT-1
1. To find the roots of non-linear equation using Bisection method
The method is also called the interval halving method, the binary search method or the dichotomy
method. This method is used to find root of an equation in a given interval that is value of ‘x’ for
which f(x) = 0 .
The method is based on The Intermediate Value Theorem which states that if f(x) is a
continuous function and there are two real numbers a and b such that f(a)*f(b) 0 and f(b) < 0),
then it is guaranteed that it has at least one root between them.
Assumptions:
1. f(x) is a continuous function in interval [a, b]
2. f(a) * f(b) < 0
Steps:
1. Find middle point c= (a + b)/2 .
2. If f(c) == 0, then c is the root of the solution.
3. Else f(c) != 0
1. If value f(a)*f(c) < 0 then root lies between a and c. So we recur for a and c
2. Else If f(b)*f(c) < 0 then root lies between b and c. So we recur b and c.
3. Else given function doesn’t follow one of assumptions.
Since root may be a floating point number, we repeat above steps while difference between a and
b is less than a value ? (A very small value).
PYTHON PROGRAMMING LAB DATE:
def func(x):
return x*x*x - x*x + 2
# Prints root of func(x)
# with error of EPSILON
def bisection(a,b):
if (func(a) * func(b) >= 0):
print("You have not assumed right a and b\n")
return
c = a
while ((b-a) >= 0.01):
# Find middle point
c = (a+b)/2
# Check if middle point is root
if (func(c) == 0.0):
break
# Decide the side to repeat the steps
if (func(c)*func(a) < 0):
b = c
else:
a = c
print("The value of root is : ","%.4f"%c)
# Driver code
# Initial values assumed
a =-200
b = 300
bisection(a, b)
OUTPUT: