Using NDSolve for a set of three ordinary differential equations, I ran into the problem that intermediate results quickly develop negligible imaginary parts. I get the error
For the method IDA, only machine real code is available. Unable to continue with complex values or beyond floating-point exceptions.
Unfortunately, the equations themselves are very long and I haven't yet been able to reproduce the issue in a simpler example, so I can't offer an MWE at this point. However, adding the option StepMonitor :> Print[{t, var1[t], var2[t], var3[t]}] to NDSolve gives
{-0.0001,0.020001,0.499998,-0.0000663528}
{-0.0002,0.0200019 +0. I,0.499997 +0. I,-0.0000663555+0. I}
So the iteration fails already in the second step. The imaginary part appears to be due to rounding errors. My question is, is it possible to apply Chop to all variables after each step? Or alternatively, is there a method other than IDA that is equipped to deal with complex numbers?
NDSolvecan work with any numerical black box, not just with symbolic equations. You can usef'[x] == fun[f[x], x]inside NDSolve and have a separate definitionfun[fx_?NumericQ, x_?NumericQ] := Chop[...]. This may not be this straightfoward if you have a differential algebraic equation though. – Szabolcs Feb 01 '17 at 17:11Re[]in the appropriate places be feasible? – J. M.'s missing motivation Feb 01 '17 at 19:16NDSolvethinks so.) A possible work-around is to modify the DAE system to an ODE system, here is an example. – xzczd Feb 02 '17 at 01:50var'[t] == Re[func[var[t]]], yet the problem persists. – Janosh Feb 02 '17 at 20:37