How to stop a loop when the variable approaches infinity?
조회 수: 3 (최근 30일)
이전 댓글 표시
I am new to MATLAB. I have to evaluate two variables i.e. X and U. I need to write an if loop (or while loop) in a script where X takes a value and does calculations on a set of equations to calculate U. The loop should stop when U approaches infinity. How can I code this MATLAB? Thank you.
댓글 수: 0
답변 (2개)
KALYAN ACHARJYA
2019년 12월 25일
편집: KALYAN ACHARJYA
2019년 12월 25일
"The loop should stop when U approaches infinity",
Matlab implementation is all about Maths, you should define it specifically.
data_value=...?? % Define max U value here, any specific (U approaches infinity)
U=...?? Initialize varaible_data
while U<data_value
%% Code
U=....% Update (Ensure that it is increasing)
end
댓글 수: 0
Image Analyst
2019년 12월 25일
If you're using a for loop
for k = 1 : 9999999
X = whatever;
U = SomeFunction(X);
if U > 1e8 % Whatever number you think is "approaching infinity".
% If U is bigger than we want to allow, break out of the loop.
break;
end
end
댓글 수: 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!