Borrar filtros
Borrar filtros

How to stop a loop when the variable approaches infinity?

3 visualizaciones (últimos 30 días)
Yousaf
Yousaf el 25 de Dic. de 2019
Respondida: Image Analyst el 25 de Dic. de 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.

Respuestas (2)

KALYAN ACHARJYA
KALYAN ACHARJYA el 25 de Dic. de 2019
Editada: KALYAN ACHARJYA el 25 de Dic. de 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 el 25 de Dic. de 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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by