Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Negative zeros in Matlab

Basically I wanted to ask two things:

  1. Why does this happen? (negative zero in Matlab)
  2. When does this happen?

I came up with this. Octave has some similarities with Matlab, so the usefulness of this feature is clear, but one of the things they said, is that it does not appear in the default output. and I just tackled it right now. So, maybe a new insight on this?

For the second question, in the answered question I referred to, they just said it could happen in some calculations, and in the following calculation which I just did, it doesn't seem really necessary to use (or get) that negative zero.

The code where I encountered this is:

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

where it's output is:

-0.0000   -0.0000    1.0000    1.0000    1.0000    2.0000    1.0000    0.0000    0.0000

The xcorr is actually a cross corelation function, which does only some simple operations like summing and multiplications, where it's exact function details can be found here. Anyway, nothing like "complex branch cuts and transformations of the complex plane"

Thanks

like image 804
lazary Avatar asked Apr 30 '16 15:04

lazary


1 Answers

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

In other words - the values which are displayed on the screen are just approximations for negative values.

In order to test 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.

like image 166
ibezito Avatar answered Oct 07 '22 23:10

ibezito