how to break from the following for loop when beta( J+1) become zero
1 回表示 (過去 30 日間)
古いコメントを表示
Nitish Reddy Kotkur
2019 年 9 月 28 日
コメント済み: Nitish Reddy Kotkur
2019 年 10 月 21 日
for j=2:inf
w = A*V(:,j) - beta(j)*V(:,j-1);
alpha(j) = w'*V(:,j);
w = w - alpha(j)*V(:,j);
beta(j+1) = norm(w,2);
V(:,j+1) = w/beta(j+1);
loopcnt = loopcnt + 1;
end
0 件のコメント
採用された回答
the cyclist
2019 年 9 月 28 日
Put this inside your loop:
if beta(j+1) == 0
break
end
You might not want to check for exact equality, because of possible floating point error. Instead, you could check like this
if abs(beta(j+1)) < 1.e-8
break
end
or use some other suitably small tolerance.
3 件のコメント
the cyclist
2019 年 9 月 28 日
As I said, you need to try a "suitably small tolerance". You could try a smaller power.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!