Why do my loop never end?

1 回表示 (過去 30 日間)
Adam
Adam 2013 年 9 月 11 日
Hi! In my function my while loop never ends and I can't understand why. I'm making the bisect algorithm and want to save every left and right x I test.
The error I get (after using ctrl + C): Operation terminated by user during bisektion2 (line 60)
The loop looks like this:
while X(i)-x(i)>tol % continue as long as the interval is longer
% than the given tolerance
i=i+1; %add 1 to i
if fxx==0
return % break and return x
end
if ((fx*fxx)<0) %if fx * fxx is <0 the answer is on the left side of the interval
X(i)=xx;
x(i)=x(i-1);
fX=fxx;
else %on the right side of the interval
x(i)=xx;
X(i)=X(i-1);
fx=fxx;
end
disp(i);
end

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 9 月 11 日
編集済み: Azzi Abdelmalek 2013 年 9 月 11 日
That means that X(i)-x(i)>tol is always true

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by