Search code examples
matlabcomplex-numbers

What does 0.2104 + 0.0000i mean in MATLAB


Some results in MATLAB seem very strange,

I get a vector of numbers like this:

0.2104 + 0.0000i
0.8404 + 0.0000i
0.2564 + 0.0000i
...

How can I convert these to a normal set of numbers?

I am completing maximum likelihood estimation and recording the p-values

here is a longer list of numbers out of my 5000

0.210375413 0.210375412872214 + 0.00000000000000i
0.053300966 0.0533009655998162 + 0.00000000000000i
0.569707287 0.569707286911292 + 0.00000000000000i
0.789479544 0.789479543799722 + 0.00000000000000i
0.792401416 0.792401416159656 + 0.00000000000000i
0.449510767 0.449510766546419 + 0.00000000000000i
0.967223276 0.967223275937553 + 0.00000000000000i
0.365126323 0.365126322610076 + 0.00000000000000i
0.572278247 0.572278247118208 + 0.00000000000000i
0.462192501 0.462192500844107 + 0.00000000000000i
0.891594566 0.891594565688343 + 0.00000000000000i
0.509256161 0.509256160918297 + 0.00000000000000i
0.195843938 0.195843938121061 + 0.00000000000000i
0.446937982 0.446937981596096 + 0.00000000000000i
0.715944643 0.715944642525015 + 0.00000000000000i
0.041095144 0.0410951439103705 + 0.00000000000000i
0.565493597 0.565493596672335 + 0.00000000000000i
0.110642354 0.110642353871931 + 0.00000000000000i
0.538977891 0.538977891429440 + 0.00000000000000i
0.633743323 0.633743322903976 + 0.00000000000000i
0.573735606 0.573735606007466 + 0.00000000000000i
0.776896023 0.776896022759461 + 0.00000000000000i
0.685299218 0.685299218035155 + 0.00000000000000i
0.273675891 0.273675891163331 + 0.00000000000000i
0.713439449 0.713439449399772 + 0.00000000000000i
0.778393872 0.778393872231057 + 0.00000000000000i
0.291038278 0.291038277535648 + 0.00000000000000i
1   0.999999999954056 - 750325.850663069i
0.884944383 0.884944383017724 + 0.00000000000000i
0.202998566 0.202998565584345 + 0.00000000000000i

It is only this one number 0.999999999954056 - 750325.850663069i in the entire 5000 that seems off. Can I just ignore the imaginary part there?


Solution

  • You are getting complex numbers. I assume you want real numbers. You can do that using the function real(). real() will capture the "real" part of the complex number, a number that is made up by real and imaginary parts, as real+imaginary, often the imaginary part labelled as i so you don't think it a sum.

    However, note: If this is the output of some computation, its likely that the maths you are doing are resulting in imaginary/complex numbers (e.g. sqrt(-1) results in 1i or just i). By your lack of knowledge of what complex numbers are and surprise at finding them, I suspect that the maths that lead to those results are not supposed to return complex numbers, and there is a high likelihood that you have a bug in your code.