MATLAB: Matlab not squaring imaginary part of complex number.

MATLABmatlab code complex number error

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

Best Answer

"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?