Negative Zeros in Matlab

Basically, I wanted to ask two things:

  • Why is this happening? (negative zero in matlab)
  • When does this happen?

I came up with this one . Octave has some similarities with Matlab, so the usefulness of this function is clear, but one of the things they talked about is that it does not appear in the output file by default. and I just got down to it now. So maybe a new understanding of this?

In the second question, in the answer to the question I was talking about, they simply said that this could happen in some calculations, and in the next calculation that I just did, it seems there is no need to use (or get) that negative zero.

Code where I came across this:

xcorr([1 0 1 1], [0 1 1 0 0]) 

where is it displayed:

 -0.0000 -0.0000 1.0000 1.0000 1.0000 2.0000 1.0000 0.0000 0.0000 

xcorr is actually a cross-correlation function that performs only some simple operations, such as summation and multiplication, where you can find the exact details of the function here . In any case, nothing like "complex cutouts and complex plane transformations"

thanks

+5
source share
1 answer

These values ​​do not represent zeros. Instead, they are negative values ​​that are very close to zero. The reason for obtaining these values, and not just zeros, is due to the approximations that are performed in the implementation of the function. According to the Matlab documentation: xcorr estimates the sequence of cross-correlation of a random process .

In other words, the values ​​displayed on the screen are approximate for negative values.

To verify this, you can change the display format of Matlab.

code:

 format shortE; xcorr([1 0 1 1], [0 1 1 0 0]) 

Result:

 ans = Columns 1 through 5 -6.2450e-017 -5.5511e-017 1.0000e+000 1.0000e+000 1.0000e+000 Columns 6 through 9 2.0000e+000 1.0000e+000 1.1102e-016 1.1796e-016 

As you can see, the values ​​in coordinates 1,2,8 and 9 are actually negative.

+3
source

All Articles