【问题标题】:Bound an odeint variable绑定一个 odeint 变量
【发布时间】:2013-01-13 05:01:49
【问题描述】:

我正在使用 odeint 来模拟一个系统,其中有几个变量不应小于零。

是否有适当的方法将 odeint 中的变量绑定到特定范围?

【问题讨论】:

    标签: c++ differential-equations odeint


    【解决方案1】:

    您需要的有时称为“饱和”约束,这是动态系统建模中的常见问题。您可以轻松地将其编码到您的等式中:

    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] = ....
        ...
    }
    

    【讨论】:

      【解决方案2】:

      odeint 中没有这种可能性。而且我想没有算法可以做到这一点。您必须以某种方式在您的 ODE 中对边界进行编码。

      如果您只想在系统演化过程中找到一个界限,请使用类似循环

      while( t < tmax )
      {
          stepper.do_step( ode , x , t , dt );
          t += dt;
          if( check_bound( x , t ) ) break;
      }
      

      两个侧节点,也许你的问题就是这种情况:

      1. 对于具有守恒定律的 ODE 有一些特殊算法,该算法确保守恒定律成立,例如,参见辛求解器。

      2. 如果您已经在 ODE 中以某种方式对边界进行了编码,并且无论如何达到了边界,则您必须缩短求解器的步长。

      【讨论】:

        猜你喜欢
        • 2017-10-12
        • 2013-07-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多