applying log to matrix converts from real to complex: why?

Hello everyone,
I'm experiencing a very strange behaviour from matlab: I have a 132x4 matrix of real numbers and I need to take their logs. Of course, if I take each number's log individually, it works fine. If I instead use the function log on the whole matrix transf = log(matrix); numbers are converted to their logs from row 1 to 64, but from row 65 to the end they are converted to complex numbers (NaNs as well).
What can this be caused by?
Thanks in advance

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 21 日
編集済み: Azzi Abdelmalek 2012 年 9 月 21 日

0 投票

maybe you have negativ numbers
log(-1.5)
it's a complex logarithm

2 件のコメント

mattia
mattia 2012 年 9 月 21 日
ok very stupid of me, just noticed there were some negative zeros, thanks for the suggestion!
Wayne King
Wayne King 2012 年 9 月 21 日
but that does not explain your claim of NaNs or that there is a difference between taking the log of individual elements and the log of the matrix.

サインインしてコメントする。

その他の回答 (1 件)

Wayne King
Wayne King 2012 年 9 月 21 日
編集済み: Wayne King 2012 年 9 月 21 日

0 投票

It makes perfect sense to me that log() can produce complex numbers, but I'm confused by the NaNs. Can you give an example of an entry in your matrix such that log(that_entry) = NaN?
Also, can you create a small matrix example such that the log of the individual elements is different than when you apply log() to the matrix.
a = randn(4,4);
log(a)
Whether they are in a matrix or not should not matter.

2 件のコメント

Matt Fig
Matt Fig 2012 年 9 月 21 日
log(nan) is the only thing I can think of here.
mattia
mattia 2012 年 9 月 21 日
yes that is what i meant. since in position 64,1 there was a negative number, i guess it treated all subsequent values as complex, so NaNs became Nan+00000000i

サインインしてコメントする。

カテゴリ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by