Matlab log (1) is not always zero

I am developing an image processing application for detecting objects.

At some point, I use the log of a generalized eigenvalue vector of two square covariance matrices. Suppose I have a 9x9 a covariance matrix.

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. 

Although we know and can debug it to see that b contains elements with a value of 1 and log (1) is 0, the contents of c:

 1.0e-014 * 0.0222 0.1110 0.0222 0.0222 -0.0777 0 0.0222 0.0888 0 

This is in my case. Does anyone know why it doesn't matter 0? Thanks.

+4
source share
2 answers

As @OliCharlesworth commented on the values ​​of b are actually not 1. I did the same as you 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 in the variable explorer, I got the following:

Ya only one true one

You will see that there is only one value of 1 , not 1.000 , which means some final values ​​that are not shown in MatLab. Therefore, you 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 

Pay attention to 1.0e-15 , where the final values ​​are found.

+5
source

Trailing zeros after a number, e.g.

1.0000

indicates that this is not quite the meaning. Try

long format

to see the final digits up to 15. If this is not enough, try the print command

Sprintf ('%. 50F', B (1))

to see 50 trailing digits of b (1).

Thus, the numbers are not equal to 1, nor does the log become exactly equal to 0.

+1
source

Source: https://habr.com/ru/post/1483422/


All Articles