我在使用 BOOST odeint 库中的 Adams-Bashforth-Moulton 方法时遇到了一些问题。我在 Bulirsch-Stoer 上取得了成功,但出于某种原因,每当我尝试使用大于 2 的阶数时,Adams-Bashforth-Moulton 只会返回 nan。如果我使用阶数 1 或 2,我会得到双倍的真实答案。我已将代码缩减为:
#include <iostream>
#include <boost/array.hpp>
#include <boost/numeric/odeint.hpp>
#include <boost/version.hpp>
typedef boost::array<long double, 2> state_type;
using namespace boost::numeric::odeint;
class Boost_odeint_rhs{
public:
Boost_odeint_rhs(){
}
void operator() (const state_type &x, state_type &dxdt, const double t)
{
dxdt[0] = 1;
dxdt[1] = 2;
}
};
int main() {
std::cout << "using boost "
<< BOOST_VERSION / 100000 << "."
<< BOOST_VERSION / 100 % 1000 << "."
<< BOOST_VERSION % 100 << std::endl;
std::cout << "integrating vector [1,2] over (0,1)" << std::endl;
Boost_odeint_rhs rhs;
state_type Bint;
Bint[0] = 0.0;
Bint[1] = 0.0;
adams_bashforth_moulton< 2 , state_type > stepper;
//bulirsch_stoer< state_type > stepper( 1e-5 , 0.0 , 0.0 , 1.0 );
integrate_adaptive( stepper , rhs , Bint , 0.0 , 1.0 , 1e-3 );
std::cout << "returned integral = " << Bint[0] << " "<< Bint[1] << std::endl;
}
我在 Ubuntu 14.04 上使用 BOOST 1.54.0 和 GCC 4.8.2
提前致谢。
最佳答案
看起来像一个奇怪的错误。当我改变
typedef boost::array< long double , 2 > state_type
到
typedef boost::array< double , 2 > state_type
它有效。但这当然不是真正的解决方案,但也许这对您来说是一种解决方法。不过,我正在尝试找出问题并提供解决方案。
更新:这是 odeint 中的错误。但它已经被修复了,修复将在下一版本的 boost 中可用(应该很快就会出现)。您还可以使用 odeint github repository 中的当前版本.
关于c++ - 无法让 BOOST odeint 与 Adams-Bashforth-Moulton 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25165248/