如何在C++中使用odeint执行简单的数字集成

Ita*_*dev 1 c++ integration numeric odeint

你能为我提供执行与数字融合的一个简单的例子odeintC++

我想使用方便的集成功能,记录为:

integrate( system , x0 , t0 , t1 , dt )
Run Code Online (Sandbox Code Playgroud)

另外我不确定,如果可能的话,如何传递它而不是函数或仿函数,类方法.

hea*_*der 5

在C++ 11中,您可以使用简单的lambda函数将调用包装到您的成员方法中

Class c;
auto f = [&c]( const state_type & x , state_type &dxdt , double t ) {
    c.system_func( x , dxdt , t ); };
integrate( f , x0 , t0 , t1 , dt );
Run Code Online (Sandbox Code Playgroud)

std::bind 也可以工作,但是如果通过值的引用传递值,则必须注意.

在C++ 03中,您需要在类方法周围编写一个简单的包装器

struct wrapper
{
    Class &c;
    wrapper( Class &c_ ) : c( c_ )  { }
    template< typename State , typename Time >
    void operator()( State const &x , State &dxdt , Time t ) const
    {
        c.system_func( x , dxdt , t );
    }
};

// ...
integrate( wrapper( c ) , x0 , t0 , t1 , dt );
Run Code Online (Sandbox Code Playgroud)

(Boost.Bind将无法正常使用两个以上的参数).