How to compare previous iteration output with current iteration output?
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Torsten
2023-1-20
xold = 2;
error = 1;
while error > 1e-6
x = xold - (xold^2-2)/(2*xold);
error = abs(x-xold);
xold = x;
end
x
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!