Using odeint function definition

北城余情 提交于 2019-12-01 08:40:55

You can use the "class" version, but modify it so that it is initialized with the R value of interest to you.

class lorenz_class {
    double R_;
public:
    lorenz_class (double r) : R_(r) {}
    void operator()( state_type &x , state_type &dxdt , double t ) {
        dxdt[0] = sigma * ( x[1] - x[0] );
        dxdt[1] = R_ * x[0] - x[1] - x[0] * x[2];
        dxdt[2] = x[0]*x[1] - b * x[2];
    }
};

Then, iterate over your vector R and pass in the value to the lorenz_class instance that you pass to the integrate_const template function.

for (unsigned i = 0; i < myR.size(); ++i) {
    lorenz_class lorenz(myR[i]);
    integrate_const( runge_kutta4< state_type >() , lorenz , x , 0.0 , 10.0 , dt );
}

Just a little side note: The tutorial shows a very similar example of a parameter study of the Lorenz system: http://headmyshoulder.github.com/odeint-v2/doc/boost_numeric_odeint/tutorial.html. It is in the Thrust and the VexCL section and it shows how you can parallelize this problem to work on multiple CPUs or the GPU.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!