Question: Creating Our Own Root Finding Function We will assume, like MATLAB does, that it only makes sense to look for roots in intervals where at

Creating Our Own Root Finding Function
We will assume, like MATLAB does, that it only makes sense to look for roots in intervals where at least one solution exists. The first part
of our function will throw out anything where the function and given interval does not contain a zero (that is the endpoints of the function
differ in sign).
function x = bisect(f, a,b,tol)
if nargin 4
tol =1e-10; % default value
end
% check input values
assert(f(a)*f(b)0,['Function values at the '...
'endpoints must differ in sign']);
assert(a b, 'a must be less than b')
end
Using this as a starting point, complete bisect. m with the following requirements:
Use a while loop that runs until your interval width is less than 2* tol
Calculate the midpoint m of the interval, then detect which interval a,m or m,b contains the sign change
Use an if statement inside the loop to change a to m or b to m depending on which interval (parts 2 and 3 may be done
simultaneously)
Once your while loop is finished, report x=m, where m is the midpoint of the final interval (this guarantees that the reported root is
within tol of the actual root).
(Exceptional Case) When the above works, add an extra elseif which detects if f(m)==0. If this happens, return m as your
answer.
Creating Our Own Root Finding Function We will

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!