bisection method disadvantage?

4 次查看(过去 30 天)
Rachel Dawn
Rachel Dawn 2018-2-26
回答: Jan 2018-2-26
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?
  5 个评论
James Tursa
James Tursa 2018-2-26
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
Jan 2018-2-26
@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.

请先登录,再进行评论。

回答(1 个)

Jan
Jan 2018-2-26
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: https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html .

类别

Help CenterFile Exchange 中查找有关 Get Started with MuPAD 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by