我使用odeint来模拟一个系统,其中有几个变量不应该小于零。
有没有一种合适的方法将odeint中的变量绑定到特定的范围?
发布于 2013-01-30 01:08:30
odeint中没有这样的可能性。我猜没有算法可以做到这一点。你必须以某种方式在你的颂歌中编码界限。
如果您只想在系统的演变过程中找到一个界限,请使用如下循环
while( t < tmax )
{
stepper.do_step( ode , x , t , dt );
t += dt;
if( check_bound( x , t ) ) break;
}两个边节点,也许你的问题就是这样:
发布于 2015-12-15 20:15:49
您所需要的有时称为“饱和度”约束,这是动态系统建模中的一个常见问题。你可以很容易地将它编码到你的方程式中:
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] = ....
...
}https://stackoverflow.com/questions/14586059
复制相似问题