In: Computer Science
PLEASE USE PYTHON CODE
2. Find the smallest positive (real) root of x^3-3.23x^2-5.54x+9.84 = 0 by the method of bisection
source code:
def func(x):
return (x*x*x) - (3.23*x*x) -(5.54*x) + 9.84
# 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)