6
$\begingroup$

I'm trying to get an eigenvalue equation in Mathematica, and the result is an expression with coefficients of the form a + 0. I. For example,

Mathematica output

Is there any clever way to simplify it? I mean the method in which I can take away the 0.*I in the expression.

$\endgroup$

1 Answer 1

7
$\begingroup$

Yes, Chop[] works nicely here.

Chop[1 + 0. I]
1.
$\endgroup$
2
  • 2
    $\begingroup$ @yulinlinyu: However note that Chop changes every approximate value near zero to zero. Usually it is what you want, but you should be aware of it for the cases when you don't want to replace a numerical value of order $10^{-11}$ or below with zero (sometimes that's just the order of magnitude your numbers are expected to be in). In such cases, the optional second argument of Chop comes in handy. $\endgroup$
    – celtschk
    Commented Jun 18, 2012 at 15:49
  • $\begingroup$ @celt: good note. At least in OP's case, this isn't a worry, but still good to be wary when your expression has a mix of genuinely tiny constants and stuff that really ought to be zero. $\endgroup$ Commented Jun 18, 2012 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.