While loop condition to execute until certain number of decimal places of accuracy is achieved
7 ビュー (過去 30 日間)
古いコメントを表示
Hi so I am trying to run something in a while loop until a certain number of decimal place is achieve:
so lets say
a = 0.003
b = 0.02
and the absolute difference between them is:
difference = abs(a-b)
and I want to increment a whilst leaving b constant until I get an Accuracy of 3 decimal places for the difference between them.
How would I go about doing this?
Thanks.
2 件のコメント
KALYAN ACHARJYA
2019 年 10 月 12 日
編集済み: KALYAN ACHARJYA
2019 年 10 月 12 日
Accurracy of 3 decimal places
Accuracy??
回答 (1 件)
David Hill
2019 年 10 月 12 日
Increment by half the difference or whatever you want.
d=1;
while d>.001
a=a+(a-b)/2;
d=abs(a-b);
end
2 件のコメント
Image Analyst
2019 年 10 月 12 日
3. It will keep going until the first 3 decimal places of the difference are 0 and there is only a non-zero difference in the 4th or later decimal places.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!