Question: implement the function using while- or for- loop and then using recursion In this problem you'll implement the bisection method. The general idea is to
In this problem you'll implement the bisection method. The general idea is to take an interval a, b where the root Ea, b exists and continually move halfway to either the left or right. I'm using the algorithm as it's presented in Elementary Analysis 2nd ed., Atkinson. You should be excited you can interpret the pseudo-code! Here is our threshold and c is the approximation to rs. B1 Define c= (a+ b)/2 B2 If b-cS T, then accept c as the root and stop. B3 If sign[f(b)] . sign(f(c)] 0, then set a c. Otherwise, set b = c. Return to step B1 You are free to implement this using for, while, or recursion, though my implementation is using a while loop. The sign) function should return -1 if the argument is non-positive (negative or zero) and return 1 if it's positive bisect I f = lambda x: x**6 - x - 1 3 def sign(x): # TO DO: Implement this function 7 def bisect(f,a,b,tau) # TO DO: Implement this function # Use the following print statement to display the data nicely # the c variable is from the algorithmic specification of the bisection method seen above print("(O:.5f (1.5f (2:.5f 13:.5f) 4:.5f".format (a,b,c,b-c,f(c)) 12 13 14 bisect (f,1.0,2.0,001) Programming Problem 2 Complete the sign0 and bisect(0 functions. Use the print supplied in the comments to display the output nicely
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
