Why does Matlab generate smal complex numbers?
21 次查看(过去 30 天)
显示 更早的评论
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
2020-3-1
Sorry not enough information about what you are doing.
That line has a complex component of exactly 0.
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!