Error when multiplying complex numbers
이전 댓글 표시
Hello, I'm having trouble multiplying complex numbers, and I have no idea why. I created a loop (for i=1:1:24) in which I calculate (among others) two complex numbers. The result being completely off, I tried running the calculations through the command window.
---------------------------------------------------------------------------------------------
>> rho
rho =
64.4787 +57.6367i
>> wp
wp =
0.0043 + 0.0049i
>> rho*wp
ans =
0.0000 + 0.5642i
%which is, of course, false. However, when I submit this calculation without resorting to values to Matlab through the command window:
>> (64.4787 +57.6367i)*(0.0043 + 0.0049i)
ans =
-0.0052 + 0.5638i
%No error here
---------------------------------------------------------------------------------------------
I don't understand how that can happen. Granted, rho, and wp will change value on each iteration, however, if I ask Matlab for their final value and multiply them out of the loop, why is the result wrong?
---------------------------------------------------------------------------------------------
Here is the complete code attached, if you run it, and try to multiply rho and wp, I suspect the result of the multiplication of rho and wp will be off.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!