Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab log(1) is not always zero

Tags:

matlab

I am developing an image processing application for object detection.

At some point I am using log of the generalized eigenvalues vector of two square covariance matrices. Assume that I have a 9x9 covariance matrix a.

a = rand(9, 9)%just generating random matrix for testing problem easily

b = eig(a, a)%generalized eigenvalues vector containing nine values equal to 1
             %so we have b = [1.000, 1.000, 1.000 ... (9 times)]

c = log(b(:)) %we know b contains values of 1. and log(1) is 0.

Even though we know and can debug to see that b contains elements with value 1 and log(1) is 0, content of c is:

1.0e-014 *

0.0222
0.1110
0.0222
0.0222
-0.0777
0
0.0222
0.0888
0

This in my case. Anyone knows why doesn't c have values of 0? Thanks.

like image 384
sderen Avatar asked May 29 '13 18:05

sderen


1 Answers

As @OliCharlesworth commented the values of b aren't really 1. I did the exact same as you did and got the following for b:

b =

    1.0000
    1.0000
    1.0000
    1.0000
    1.0000
    1.0000
    1.0000
    1.0000
    1.0000

But when I opened b up in the variable explorer I got the following:

Ya only one true one

You'll see that there's only really one value of 1 and not 1.000 meaning that there are some trailing values that aren't shown in MatLab. Hence you would get the following for c:

c =

   1.0e-15 *

    0.2220
   -0.4441
    0.2220
   -0.2220
    0.2220
         0
    0.2220
   -0.1110
   -0.1110

Notice the 1.0e-15 that's where trailing values are being found.

like image 169
James Mertz Avatar answered Sep 26 '22 23:09

James Mertz