Question: Implement a function bisection, that can operate on an arbitrary function. Your program should accept: a function (f to find the roots/zeros of); two endpoints


Implement a function bisection, that can operate on an arbitrary function. Your program should accept: a function (f to find the roots/zeros of); two endpoints (x0, x1); a tolerance limit () and the max. number of iterations m as input parameters. The function bisection should output the final approxima- tion to the root (zero) and the number of iterations it took to find the root. The program should make sure that the initial interval is acceptable for this method (i.e. (i) it should be greater than the tolerance (e) and (ii) must contain a zero of f (i.e. f(x0) f(x1) 2n+1 In 2 Set this value as your max. iterations m . The bisection method for finding roots was covered in class. The algorithm is in the notes on-line. Notel: Define Python functions for function evaluations in the problems: Note2: You can return two values from a python function using return rootApprox, iterCount as the final line in the function. Make sure to pick up both values in the calling code as: xr, numIter = bisection(a, b, tol, f) for example. Use the bisection(f, x0, x1, tol, m) to compute (i) the positive root of f(x) : x2 X 1. The positive root of this equation is known to lie in the interval [1,2]. Use a tolerance of f 10-8. (ii) Repeat this exercise for the negative root:. Search in (-1,0). (The solution to (i) is the Golden Ratio: 0 the limit of = 1 the ratio of consecutive Fibonacci numbers. The solution to (ii) is known to be -1/9). Use your program to compute the roots of f1(x) = x2 3x 1 on [0, 1], f2(x) = x3 2 sin(x) on (0.5, 2), fz = tan(x) 2x on (0, 2). Start by plotting the functions to find a reasonable interval to bracket the root and print x, | f(x) | and the number of iterations required for convergence
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
