绑定一个 odeint 变量
Bound an odeint variable
我正在使用odeint来模拟一个系统,其中有几个变量不应该小于零。
有没有合适的方法将 odeint 中的变量绑定到特定范围?
在odeint中没有这种可能性。我想没有算法可以做到这一点。您必须以某种方式对 ODE 中的绑定进行编码。
如果您只想在系统演变过程中找到一个边界,请使用类似
while( t < tmax )
{
stepper.do_step( ode , x , t , dt );
t += dt;
if( check_bound( x , t ) ) break;
}
两个侧节点,也许您的问题就是这种情况:
- 对于
具有守恒定律的常微分方程,有一些特殊的算法,其中算法确保守恒定律成立,例如参见辛求解器。
如果绑定已经在 ODE 中以某种方式进行了编码,并且无论如何都达到了边界,则必须缩短求解器的步长。
您需要的有时称为"饱和"约束,这是动态系统建模中的常见问题。您可以轻松地在公式中对其进行编码:
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] = ....
...
}
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 运行同一解决方案的另一个项目的项目
- 挂起和取消挂起一个文件DLL
- 用C++中的一个变量定义一个常量
- 函数向量_指针有不同的原型,我可以构建一个吗
- 在c++中用vector填充一个简单的动态数组
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 预处理器:插入结构名称中的前一个行号
- 我在c++代码中生成了一个运行时#3异常
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 从链接列表c++中删除一个项目
- 告诉一个 const char 数组,除了编译时 C 样式的字符串外,它不以 '