How to compare previous iteration output with current iteration output?

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.

답변 (1개)

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2023년 1월 20일

답변:

2023년 1월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by