gpt4 book ai didi

c++ - 在 C++ 中及时求解 ODE 系统

转载 作者:行者123 更新时间:2023-11-28 00:03:04 24 4
gpt4 key购买 nike

不幸的是,我注意到 BOOST 的 odeint 无法及时解决 ODE 系统,即当我改变条件时

typedef std::vector< double > state_type;

void ode_function(const state_type &x, state_type &dxdt, const double
{
dxdt[0] = x[0];
}

using namespace std;
using namespace boost::numeric::odeint;

state_type x(1);
x[0] = std::exp(1);


runge_kutta4< state_type > stepper;
integrate_const(stepper, ode_function, x, 1., 0., 0.01);

cout << x[0] << endl;

这实际上什么都不做,并返回初始条件不变。在这个简单的例子中,可以通过改变变量 s=-t 来解决这个问题。但是,我不确定这个技巧是否适用于任何 ODE 系统。当我在我的程序中使用它时,我不确定它是否给出了正确的结果。因此,有谁知道任何允许向后时间积分的 c++ 库?

最佳答案

在 odeint 中,如果您想及时向后积分,您还必须使用负步长。在您的情况下,您应该使用 -0.01 作为 integrate_const 函数中的最后一个参数。

关于c++ - 在 C++ 中及时求解 ODE 系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37467368/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com