log of a vector

64 ビュー (過去 30 日間)
Yaser Khojah
Yaser Khojah 2018 年 9 月 27 日
コメント済み: Yaser Khojah 2018 年 9 月 28 日
I need a help with taking the log of vector C, however when I do it I get some complex numbers. I understand this happens for the negative element but why all the answers are complex. When I take the log for each element individually I do not see that. Can any help please.
if true
% code
c = [1.5906 1.4191 1.1537 0.97438 1.6484 -0.29514 1.2085 0.69238]
log (c)
end
This is what I see after taking the log; is there away to show it with out the i for the non-complex case: 0.464128588916044 + 0.00000000000000i 0.349995805662481 + 0.00000000000000i 0.142979230072927 + 0.00000000000000i -0.0259551554779898 + 0.00000000000000i 0.499827232077424 + 0.00000000000000i -1.22030026884339 + 3.14159265358979i 0.189366422721591 + 0.00000000000000i -0.367624437313319 + 0.00000000000000i

採用された回答

Guillaume
Guillaume 2018 年 9 月 27 日
A real number is a complex number with an imaginary part equal to 0. If you look at the result of your log you'll see that the complex numbers corresponding to the positive values all have imaginary part of 0.
When an array has at least one complex value (with non-zero imaginary part) matlab will display all numbers in complex notation. There is nothing you can do about that but always remember to look at the imaginary part.
  1 件のコメント
Yaser Khojah
Yaser Khojah 2018 年 9 月 27 日
Thanks for your detailed explanation. So the complex notation does not impact the model in the case the number is not complex?

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

その他の回答 (2 件)

Adam Danz
Adam Danz 2018 年 9 月 27 日
Matlab will return a vector in complex-number format if any of the elements in the input are negative.
log([2, -2])
ans =
0.69315 + 0i 0.69315 + 3.1416i
However, notice in my example the log of 2 doesn't include an imaginary component. To verify that, use imag() to isolate the imaginary components:
imag(log([2, -2]))
ans =
0 3.1416
  1 件のコメント
Yaser Khojah
Yaser Khojah 2018 年 9 月 28 日
Thanks Adam for your help

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

カテゴリ

Help Center および File ExchangeSIL, PIL, and HIL Tests についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by