0% found this document useful (0 votes)
99 views

To Find The Roots of Non-Linear Equation Using Bisection Method

This document provides instructions for using the bisection method to find the root of a non-linear equation. The bisection method iteratively narrows down the range that contains the root by dividing it in half. It assumes the function is continuous in the given range and its values at the endpoints have opposite signs. The steps find the midpoint of each range, check if it is the root, and recursively search half of the range based on the midpoint value. The Python code implements this by taking a function, initial range, and calling the bisection method which prints the estimated root.

Uploaded by

manjula mandava
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

To Find The Roots of Non-Linear Equation Using Bisection Method

This document provides instructions for using the bisection method to find the root of a non-linear equation. The bisection method iteratively narrows down the range that contains the root by dividing it in half. It assumes the function is continuous in the given range and its values at the endpoints have opposite signs. The steps find the midpoint of each range, check if it is the root, and recursively search half of the range based on the midpoint value. The Python code implements this by taking a function, initial range, and calling the bisection method which prints the estimated root.

Uploaded by

manjula mandava
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PYTHON PROGRAMMING LAB DATE:

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:

Input: A function of x, for example x3 - x2 + 2.


And two values: a = -200 and b = 300 such that
f(a)*f(b) < 0, i.e., f(a) and f(b) have
opposite signs.
Output: The value of root is : -1.0025
OR any other value with allowed
deviation from root.
SOURCE CODE:

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:

The root of the equation is :-1.0025

You might also like