Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions

Question

Intuitively, would you keep it in? Test

Answered: 1 week ago

Question

What would the Prime Minister suggest? Explore

Answered: 1 week ago

Question

Does it meet the criteria set in the Challenge stage?

Answered: 1 week ago