When I sum a complex number and its conjugate, that have been obtained when calculating the eigenvalues of a matrix, there is still an imaginary part that is equal to zero.

ev = {-0.8957457857324409` + 3.0607525560671736` I, 
      -0.8957457857324409` - 3.0607525560671736` I};

ev[[1]] + ev[[2]]

(* Out: -1.79149 + 0. I *)

How I eliminate the imaginary part if it is zero, to have a pure real number?

Using something like Re[-1.79149 + 0. I] is not sufficient as the summation of the eigenvalues that are calculated sometime have an imaginary part.

  • 5
    $\begingroup$ Use Chop on the result? $\endgroup$ – MarcoB May 3 '18 at 15:28
  • $\begingroup$ @MarcoB, that is correct! $\endgroup$ – jarhead May 3 '18 at 15:30
  • 6
    $\begingroup$ I don't like Chop because it might unpack arrays (it may change the type from Complex to Real or to Integer. I would advice something like Threshold[#, 100 $MachineEpsilon] & instead. $\endgroup$ – Henrik Schumacher May 3 '18 at 15:32

Browse other questions tagged or ask your own question.