필터 지우기
필터 지우기

How to stop a loop when the variable approaches infinity?

조회 수: 3 (최근 30일)
Yousaf
Yousaf 2019년 12월 25일
답변: Image Analyst 2019년 12월 25일
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.

답변 (2개)

KALYAN ACHARJYA
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

Image Analyst
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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by