why I get "complex number" for the common calculation?

2 ビュー (過去 30 日間)
vx2008
vx2008 2017 年 2 月 8 日
回答済み: John D'Errico 2017 年 2 月 8 日
RSTR=sum(wt.*log(rt1./rft1));
'wt', 'rt1' and 'rft1' are all real numbers and why 'RSTR' is complex numbers?
Z=log( bsxfun(@rdivide,(1+rt21),(1+rft21)) );
'rt21', and 'rft21' are both real numbers and why 'Z' is complex numbers?

採用された回答

John D'Errico
John D'Errico 2017 年 2 月 8 日
There is only one reason why you are getting a complex result there if everything is truly a real number. At least one of the elements of the set of ratios (rt21./rft21) is a negative number. It will take only one such pair that yields something negative.
log(-eps)
ans =
-36.0436533891172 + 3.14159265358979i
As you can see, the log of a negative number, even a very tiny one will have an imaginary part that is i*pi, where i is sqrt(-1).

その他の回答 (1 件)

Naty Shemer
Naty Shemer 2017 年 2 月 8 日
Most probably (rt1./rft1) is negative and the log output of a negative number is imaginary...

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by