Filter löschen
Filter löschen

How to stop a loop when the variable approaches infinity?

3 Ansichten (letzte 30 Tage)
Yousaf
Yousaf am 25 Dez. 2019
Beantwortet: Image Analyst am 25 Dez. 2019
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.

Antworten (2)

KALYAN ACHARJYA
KALYAN ACHARJYA am 25 Dez. 2019
Bearbeitet: KALYAN ACHARJYA am 25 Dez. 2019
"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 am 25 Dez. 2019
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

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by