我有一些困难,从BOOST odeint库获得亚当斯-巴什福斯-莫尔顿方法工作。我在Bulirsch-Stoer上取得了成功,但由于某种原因,亚当斯-巴什福斯-穆尔顿每次尝试使用订单> 2时都会返回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
提前谢谢。
发布于 2014-08-06 21:53:14
看上去是个奇怪的错误。当我改变
typedef boost::array< long double , 2 > state_type
至
typedef boost::array< double , 2 > state_type
它起作用了。当然,这不是一个真正的解决方案,但也许这是一个解决办法。不过,我正试图找出问题的所在,并提供解决办法。
更新:--这是odeint中的一个bug。但是它已经被修复了,并且将在下一个版本的boost中得到修复(很快就会出现)。您还可以使用来自odeint github储存库的当前版本。
https://stackoverflow.com/questions/25165248
复制相似问题