Question: Implement the bisection method as a function: function [ p , n ] = bisect ( f , a , b , tol ) We

Implement the bisection method as a function:
function [p,n]= bisect(f,a,b,tol)
We seek a root of the anonymous function in the interval . The function should return an approximation that is within a user input of the actual root by stopping when the length of the interval is less than as well as the number of iterations it took to converge.
As a class convention, we will take to be the midpoint of the first interval smaller than .
As a class convention, we will count the first bisection as the midpoint of the supplied interval .
You do not need to stop and output the midpoint when the midpoint happens to be a root, but you can if you want to. Just make sure you select the correct half interval in each step.
Debugging tips:
If your code times out, you might be using < when you need you use <=. If the midpoint of an interval is a root, and you use <, you could miss that root.
If you are receiving an error message Unrecognized function or variable 'p' along with other errors and no test passed, check your stopping criteria. If you use the incorrect stopping criteria, your code will go into an infinite loop on one of the tests and never finish (so no outputs will be defined, hence the error message). There may be other problems, but this is most likely the cause.
If test 1 is your only correct test, you are actually very close to correct code! It is likely that you stopped when the interval was shorter than tol, however, your value of p was not the midpoint of this interval. If you correct this, it is likely that this will provide passing results on all tests.
If you number of iterations n is off by one, try changing your initialization of n and/or the location of udating n in the loop. The first bisection (n=1) counts as the midpoint of the first interval.

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!