Why does Matlab generate smal complex numbers?

조회 수: 25 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by