Matlab not squaring imaginary part of complex number.

28 views (last 30 days)
For some reason Matlab is ignoring the complex part of the imaginary number in the equation. The equation is squared, so the complex numbers should go away on their own, however, Matlab seems to not be doing this and in the end I receive a 'imaginary parts of X and or Y arguments ignored' error. Any ideas on why this is? Untitled.jpg

Accepted Answer

Guillaume
Guillaume on 20 Dec 2018
Edited: Guillaume on 20 Dec 2018
"The complex number is being squared and should result in a real answer with no complex part at all"
Huh? Certainly not. . You'll only get a real output if your input number is pure imaginary or pure real.
So you can get complex numbers out of a square and as per Madhan's answer if you try to plot that, matlab will discard the imaginary part for the plot and warn you.
Now if the input to acos is pure real, then acos should return either a pure real or a pure complex number which when squared will be pure real, so it would seem that your input to acos is complex. You haven't supplied enough information for us to know why.
In any case, have you used the debugger to find out what is really happening with your code instead of what you think is happening?

More Answers (2)

madhan ravi
madhan ravi on 20 Dec 2018
  2 Comments
Gregorovich
Gregorovich on 20 Dec 2018
This is not a solution. The complex number is being squared and should result in a real answer with no complex part at all. The answer should be completely real. But for some reason this error still shows.

Sign in to comment.


James Tursa
James Tursa on 20 Dec 2018
Edited: James Tursa on 20 Dec 2018
Squaring complex numbers does not in general result in real numbers. It all depends on the phase angles involved (would need to be pure imaginary or pure real) as to whether you get a real result or not. Maybe you mean for this
Re1 = (acos(t)).^2
to be this instead using the complex conjugate
acost = acos(t);
Re1 = conj(acost) .* acost;
or
Re1 = abs(acos(t)).^2;

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!