Using Boost::odeint with Eigen::Matrix as state vector

為{幸葍}努か 提交于 2019-11-29 05:59:15

You only need to replace the definition of the stepper by

runge_kutta_dopri5<state,double,state,double,vector_space_algebra> stepper;

Eigen should work out of the Box with the vector_space_algebra but you need to specify them manually. In the next odeint version we have a mechanism for automatically detecting the algebra.

Btw. youe definition of the ODE is not correct, you need a reference for the derivatve

stepper.do_step([](const state &x, state &dxdt, const double t) -> void { 
    dxdt = x;
}, X0, 0.0, xout, 0.01);

This solution does not seem to work for adaptive integrator

typedef runge_kutta_dopri5<state,double,state,double,vector_space_algebra> stepper_type;
auto rhs = [](const state &x, state &dxdt, const double t) -> void { dxdt = x;}
integrate_adaptive( make_controlled<stepper_type>( 1E-12 , 1E-12 ), rhs , X0 , 0. , xout , 0.01;)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!