Question: Write a program that uses the bisect method to find the root of a function. (Must Be in Python) Translate the pseudo code given into

Write a program that uses the bisect method to find the root of a function. (Must Be in Python)

Translate the pseudo code given into Python using a while loop.

Pseudo Code:

def f(x):

return 3*x**3 - 4*x**2 + 2*x - 5

INPUT: Function f, endpoint values a, b, tolerance TOL, maximum iterations NMAX CONDITIONS: a < b, either f(a) < 0 and f(b) > 0 or f(a) > 0 and f(b) < 0 OUTPUT: value which differs from a root of f(x)=0 by less than TOL

solutionFound = False N 1 While N NMAX # limit iterations to prevent infinite loop c (a + b)/2 # new midpoint If f(c) = 0 or (b a)/2 < TOL then # solution found Output(N,c) solutionFound = True exit loop EndIf N N + 1 # increment step counter If sign(f(c)) = sign(f(a)) then a c else b c # new interval EndWhile If solutionFound is not True then Output("Method failed.") # max number of steps exceeded EndIf """ print("a = left bracket point (x value)") print("b = right bracket point (x value)") print("TOL = how close to true answer is acceptable") print("NMAX = maximum allowable iterations") print()

a, b, TOL, NMAX = eval(input("Enter a, b, TOL, NMAX: "))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!