c++ - 无法让 BOOST odeint 与 Adams-Bashforth-Moulton 一起工作

标签 c++ boost

我在使用 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/

相关文章:

c++ - 隐写术 : Encoded audio and video file not being played, 已损坏。什么问题

c++ - Most Vexing Parse 的目的是什么?

c++ - vector 中没有查找(元素)方法

c++ - 使用 boost::serialization 序列化一个包含作为成员的 boost adjacency_list 的类

c++ - 将派生类的构造函数中的项插入基类的私有(private) std::vector 的最佳方法?

c++ - OpenCV 随机决策森林 : How to get posterior probability

c++ - 带有 boost::fast_pool_allocator 的模板模板参数

c++ - boost 池的 map ?

c++ - 灵气: How can I write a nonterminal parser?

c++ - boost::crc_32_type 会产生任何异常吗?