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

bisection dev

The document contains a Python program that implements the Bisection Method to find the root of the equation x^3 - x^2 + 2. It defines a function to calculate the value of the equation and a bisection function to iteratively narrow down the interval to find the root. The program outputs the root value as approximately -0.9972.

Uploaded by

Dextro leo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

bisection dev

The document contains a Python program that implements the Bisection Method to find the root of the equation x^3 - x^2 + 2. It defines a function to calculate the value of the equation and a bisection function to iteratively narrow down the interval to find the root. The program outputs the root value as approximately -0.9972.

Uploaded by

Dextro leo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

@author: Devesh Deshmukh

PRN: 10303320181161210034

BATCH: B 2nd year mechanical Engineering

"""

INPUT:

#Python program for implementation

#of Bisection Method for

#solving equations

# An example function whose

#solution is determined using

# Bisection Method.

# the function is x^3 - x^2+2

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=-400

b = 500

bisection(a, b)

OUTPUT:

Python 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]

Type "copyright", "credits" or "license" for more information.

IPython 7.8.0 -- An enhanced Interactive Python.

runfile('D:/dev_python/bisection.py', wdir='D:/dev_python')

The value of root is : -0.9972

You might also like