Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using functions that are only well-defined for real values (e.g. HeavisideTheta) within NDSolve.

Internally NDSolve works, of course, with complex numbers and sometimes returns a numerically vansihing complex value (e.g. 0.` i) that breaks these functions.

Is it possible to get rid of the complex part (like applying Chop at each step)?

share|improve this question
It would be good to provide a simple example demonstrating the problem, for people to test possible answers with. – Simon Woods Nov 18 '13 at 21:48

Instead of getting rid of the small complex part after each internal step of NDSolve, I would make the projection before feeding those wimpy functions:

unbreakableHeavisideTheta[x_] := HeavisideTheta[Chop[x]]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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