Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Error while assigning a variable
1 回表示 (過去 30 日間)
古いコメントを表示
if I assign x a value of 16.000001 then it stores 16.00000100000001... and if I assign x avalue of 15.000001 then it stores 15.00000099999999.. . How to remove this error
0 件のコメント
回答 (2 件)
dipak nigam
2020 年 7 月 2 日
You can refer to this answer to understand the above behaviour.
A possible workaround is to define these values as:
xN = 15000001;
yN = 16000001;
D = 1000000;
and then use them in your calculations for best possible precision.
0 件のコメント
Shubhankar Poundrik
2020 年 7 月 2 日
Hi Himanshu,
I understand that you are trying to store floating point numbers in variables and are not sure why the value in the variable is slightly different from what you entered.
This problem occurs because not all floating point numbers can be accurately represented in binary format. To store the float (floating point number) a certain number of bytes are used, and the binary representation of the float may have 1s beyond what can be stored in the available bytes.
Read for more detailed explanation :
Regards,
Shubhankar.
1 件のコメント
Walter Roberson
2020 年 7 月 2 日
Statistically, the fraction of real numbers that can be stored as floating point, is zero. There are
real numbers, but less than
floating point numbers, and a finite non-zero number divided by an infinite quantity gives 0.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/325489/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/325492/image.png)
この質問は閉じられています。
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!