Write a script in Matlab into a function that uses the bisection method to fnd t
ID: 2895054 • Letter: W
Question
Write a script in Matlab into a function that uses the bisection method to fnd the root of f(x). The function header for the bisection method should read:
function[r, iters] = bisectionF(f, xL, xR) where the inputs are:
f = the function for which you want to find the root, xL, xR = the left and right limits of the interval, and the outputs are:
r = the root
iters = number of iterations performed.
These inputs/outputs are a minimum. You can use more inputs/outputs if you want, to make the code more general. Run this code on the piecewise function:
f(x) = x 3 + 3x + 1, x <= 0
x 0 1 + sin(x), x > 0
with the bounds xL = 2, xR = 0.1.