bisection method disadvantage?

2 views (last 30 days)
Rachel Dawn
Rachel Dawn on 26 Feb 2018
Answered: Jan on 26 Feb 2018
So, I wrote code for a function to find its roots using the bisection method. I used initial guesses x=4 and 6, knowing that there are no zeros between this interval. When I use the bisection method with the following while loop condition:
while iteration<=30 || abs(xb-xa)> 10^-4
Matlab will spit out that the root in this interval = '6'. What is it about this function/graph interval (from 4 to 6) that makes the bisection method gives me a false zero?
Does it have to do with the graph looking like a straight, horizontal line in this interval?
James Tursa
James Tursa on 26 Feb 2018
You state "... the code is correct ..." and also that the code will "... give me an answer for a root that is not zero ..."
These two statements seem to be mutually exclusive. But again, we can't help you until you show us the code and how you are calling the code. How can we possibly know where a logic error or argument input error is unless we see your code?
Jan on 26 Feb 2018
@Rachel: You ask us why your code produces a certain output, but do not want to show us the code? This cannot work.
Does it have to do with the graph looking like a straight,
horizontal line in this interval?
This is a bold guess. Guessing does not help in computer science. Remember that the data are stored in doubles with 15 significant digits. There is no way to observe straightness by looking on the data.
Your initial interval is [4, 6] and 6 is the final output. Another bold guess is, that your algorithm returns the upper limit, if no zero is contained in the interval.

Sign in to comment.

Answers (1)

Jan on 26 Feb 2018
Actually your should be able to find out by your own, why this value is replied. Simply use the debugger to step through your code line by line: .

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!