Problems with while loop
2 次查看(过去 30 天)
显示 更早的评论
Hi, I have a problem, I want the subtraction d1 to be less than 1 * 10 ^ -15 after several iterations, but the program stays busy.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/353714/image.jpeg)
2 个评论
James Tursa
2020-8-31
Please post your code as regular text and highlight it with the CODE button. We can't run pictures.
采纳的回答
Bruno Luong
2020-8-31
编辑:Bruno Luong
2020-8-31
"Hi, I have a problem, I want the subtraction d1 to be less than 1 * 10 ^ -15 after several iterations, but the program stays busy."
Well you cannot demand floating point error to be that small.
Double IEEE has about 15 digits relative precision. You compare B1 to (y/k0) which is -7699432.66755457. The most you can demand is error is about
>> tol = eps(y/k0)
tol =
9.31322574615479e-10
So if you replace the break condition by
tol = eps(y/k0);
while tt>tol
...
end
your while loop will stop.
更多回答(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!