how to break from the following for loop when beta( J+1) become zero
조회 수: 1 (최근 30일)
이전 댓글 표시
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!