c++ odeint output “not a number”
Pregunta
I am working with the c++ boost/odeint to integrate chemical reaction networks. Everything works fine except when I eliminate some of the reactions. Then there are sometimes -nan's in the output. here is a small portion of that output. first column is the time and the others are concentrations of the species.
0.0 2.8701 3.4354 3.48348 4.30509 5.43538 5.35687 2.9138 5.31905 3.51382 0.0268472 -nan 2.93435 -nan -nan -nan -nan 2.9138 -nan -nan 0.0695729 -nan 2.28324 -nan -nan -nan -nan 2.9138 -nan -nan 0.112299 -nan 1.77661 -nan -nan -nan -nan 2.9138 -nan -nan 0.155024 -nan 1.3824 -nan -nan -nan -nan 2.9138 -nan -nan 0.19939 -nan 1.06535 -nan -nan -nan -nan 2.9138 -nan -nan
The second species only depends on itself and the 7th species is constant.
So my question is: When does odeint give a -nan as output? Maybe there is a 0/0 devision somewhere, but all equations contain only products e.g.
dxdt[5] = - c[2] * x[5] + c[3] * x[9] * x[3];
Thank you very much for any advice.
Solución 2
I read somewhere else that the step size can be a problem. So I just reduced the initial step size dt by a factor 10 and now it is working. Maybe the initial slope was to large for some of the species. Thanks for the replies!
Why is it that you struggle days with the answer and as soon as you ask it on stackoverflow you find it yourself? :D
Otros consejos
Well there are several possible reasons for NaN:
- Division by zero
x/0
- Dividing +- Infinity with itself
Infinity / Infinity
- Multiplication
0 × (+- Infinity)
- Adding / subtracting Infinity to itself (e.g.
Infinity - Infinity
) Any operation with NaN
will also result in NaN
So most likely, something of the mentioned above happens in your code. A NaN in IEEE 754 is in the form where all exponent bit = 1, yet the mantissa bits and not. The leading bit indicates + or - NaN.