matlab - matlab 精度 num2string

标签 matlab precision

我有一些关于 MatLab 中 num2str() fctn 精度的问题。

a=0.11111111111111;
b=a;

Linux/OSX: num2str(a+b,25): ans=0.2222222222222221655465116
Windows: num2str(a+b,25): ans= 0.222222222222222

谁能解释一下使用 Linux/OSX 系统时小数点后 15 位之后的数字是从哪里来的? num2str() 可以获得的最大精度是多少?

num2str 文档中有一些我不完全理解的提示。

Note:   If you specify precision to exceed the precision of the input floating-point data type, the results might not match the input values to the precision you specified. The result depends on your computer hardware and operating system.

最佳答案

看看 eps ( https://de.mathworks.com/help/matlab/ref/eps.html ),它为您提供浮点相对精度,这取决于您的系统架构。

进一步查看此处:https://de.mathworks.com/matlabcentral/answers/26458-machine-epsilon :

It roughly means that numbers are stored with about 15-16 digits of precision. If a number is approximately 1, then that means it can be stored with an error of around 10^(-16)

[...]

d = eps(X) is the positive distance from abs(X) to the next larger in magnitude floating point number of the same precision as X"

That says that d = eps(1) is the smallest positive value such that (1+d) is exactly representable and is different than 1.

1+eps(1) is the smallest representable number greater than 1, a single bit difference in the least significant (smallest change) bit.

也可以看看这里,了解更多关于它的一般信息(因为它并不是真正的 MATLAB 特定主题):https://en.wikipedia.org/wiki/Machine_epsilon

关于matlab - matlab 精度 num2string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37073697/

相关文章:

将小数点后的值转换为较小的精度

iphone - 如何在 iPhone 上使用 Swift 数据类型 Float80

linux - 通过 matlab for ubuntu 启动 libreoffice

java - 防止 MATLAB 更改 Java 外观

arrays - 在 MATLAB 中使用矩阵进行矩阵索引

performance - 为什么 MATLAB 在矩阵乘法中如此之快?

c++ - 当存在 float 精度问题时,如何实际解决凸包?

arrays - 如何在matlab中给定一组链接和边找到邻接矩阵

c++ - 比较 double 和 int,无需转换或转换

rust - 我什么时候应该使用 usize vs i32, f32?