Why does Matlab generate smal complex numbers?

22 ビュー (過去 30 日間)
Abdelrazik Essam eldin
Abdelrazik Essam eldin 2020 年 3 月 1 日
コメント済み: Walter Roberson 2020 年 3 月 1 日
Hi all,
why do i get very small complex numbers like this 2.339787366554155e+02 + 0.000000000000000e+00i ?
NOTE: There is no sqrt for negative numbers
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 3 月 1 日
Sorry not enough information about what you are doing.
That line has a complex component of exactly 0.

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

採用された回答

John D'Errico
John D'Errico 2020 年 3 月 1 日
編集済み: John D'Errico 2020 年 3 月 1 日
In the example you show, you are probably taking ONE element from a vector or array of numbers, an ensemble that contains at least ONE element that is complex. For example...
A = rand(5,1);
A (2) = A(2) + sqrt(-1)
A =
0.276025076998578 + 0i
0.679702676853675 + 1i
0.655098003973841 + 0i
0.162611735194631 + 0i
0.118997681558377 + 0i
As you can see, MATLAB seems to indicate that there are 5 COMPLEX numbers, even though we know that only one was truly complex. Depending on the display format employed, you may find those zero imaginary terms being displayed as 0.000000000000000e+00i .
Why do SOME of the elements in your array or vector contain complex results? That is difficult to know, however, a complex number is not generated only when you have a sqrt. In fact, it is trivially easy to find other expressions that yield a complex result.
asin(1.1)
ans =
1.5707963267949 - 0.443568254385115i
log(-2)
ans =
0.693147180559945 + 3.14159265358979i
So just because you lack a sqrt in your code, don't immediately decide that you could NEVER have a complex result of any sort. That might be a hasty conclusion, and probably a false one, since somewhere you probably did generate something with an imaginary part in it. What you did? That we cannot know, since it is difficult to see inside your computer.
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 3 月 1 日
A.^B will turn out complex if A is negative and B is not an integer.

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

その他の回答 (0 件)

カテゴリ

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