问题描述
我正在做一些计算,最终遇到了这个问题,该问题没有得到零.在我的方程式中,理论部分建议结果为零,但是Matlab抛出非常小的无意义数z = -4.4409e-16
. z
此处应为零.在此处,已经讨论了为什么会发生此问题.我试图将此值传递给cos()
以获得一个结果,实际上我得到了一个.我的问题是现在Matlab将此值视为零还是按原样对待?另一个问题是,我应该将此值假定为哪个级别为零,以便可以将其重新分配为零?
I'm doing some calculations and I ended up with this problem which is not getting zero. In my equation, the theoretical part suggests the result to be zero however Matlab throws very small non sensible number z = -4.4409e-16
. z
here should be zero. In here, the problem has been discussed why this occurs. I've tried to pass this value to cos()
to get one as a result and indeed I got one. My question is now does Matlab treat this value as a zero or it is treated as is? Another question is to which level should I assume this value to be zero so that I can reassign this value to be zero?
推荐答案
它不为零,它是您看到的值.虽然并没有严格的规则来确定您可以将什么视为零(如果不是零,则为零),但是有一个函数将为给定的数据类型返回有用的数字,这将对您有所帮助您可以确定明显的幅度, eps
:
It's not zero, it is the value you see. While there is no hard-and-fast rule for deciding what you can treat as zero (if anything other than zero), there is a function that will return a useful number for a given data type that help you decide what a significant magnitude is, eps
:
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.
或者您也可以不使用输入变量来调用它:
Or you can call it with no input variable:
eps, with no arguments, is the distance from 1.0 to the next larger double precision
number, that is eps with no arguments returns 2^(-52).
例如,
>> eps
ans =
2.2204e-16
>> eps('double')
ans =
2.2204e-16
>> eps('single')
ans =
1.1921e-07
由于通常会依次计算多个浮点运算,因此您获得的值可能会更高(在您的情况下).如果您不十分关心精度,则可以考虑将eps
的倍数设为零.
Because there are often multiple floating point operations computed in sequence, the values you get are likely to be higher (and are in your case). If you aren't terribly concerned with precision, you can probably consider a multiple of eps
to be zero.
这篇关于变得非常小的数字而不是零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!