bisection method disadvantage?

3 ビュー (過去 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 件のコメント
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 .

Community Treasure Hunt

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

Start Hunting!

Translated by