Effacer les filtres
Effacer les filtres

How to stop a loop when the variable approaches infinity?

3 vues (au cours des 30 derniers jours)
Yousaf
Yousaf le 25 Déc 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.

Réponses (2)

KALYAN ACHARJYA
KALYAN ACHARJYA le 25 Déc 2019
Modifié(e) : KALYAN ACHARJYA le 25 Déc 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 le 25 Déc 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

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by