How to compare previous iteration output with current iteration output?

3 visualizaciones (últimos 30 días)
ASHA PON
ASHA PON el 20 de En. de 2023
Respondida: Torsten el 20 de En. de 2023
I have a program with for loop having 1to 500. I need to compare the output of previous and current iteration, if the outputs are matching the program has to stop. Otherwise the loop has to continue till the match is achieved.

Respuestas (1)

Torsten
Torsten el 20 de En. de 2023
xold = 2;
error = 1;
while error > 1e-6
x = xold - (xold^2-2)/(2*xold);
error = abs(x-xold);
xold = x;
end
x
x = 1.4142

Categorías

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

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by