I\'m using odeint to simulate a system wherein there are several variables which should not go less than zero.
Is there an appropriate way to bound a variable in ode
What you need is sometimes called a "saturation" constraint, a common issue in dynamic systems modeling. You can easily code it inside your equation:
void YourEquation::operator() (const state_type &x, state_type &dxdt, const time_type t)
{
// suppose that x[0] is the variable that should always be greater/equal 0
double x0 = x[0]; // or whatever data type you use
dxdt[0] = .... // part of your equation here
if (x0 <= 0 && dxdt[0] < 0)
{
x0 = 0;
dxdt[0] = 0
}
// the rest of the system equations, use x0 instead of x[0] if necessary, actually it depends on the situation and physical interpretation
dxdt[1] = ....
dxdt[2] = ....
...
}