Error when multiplying complex numbers
Show older comments
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.
Accepted Answer
More Answers (0)
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!