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.
Explanation / Answer
clc ; clear all; if a,b 0 disp('Wrong choice') else p = (a + b)/2; err = abs(f(p)); while err > 1e-7 if f(a)*f(p)Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.