使用odeint函数定义 [英] Using odeint function definition

查看:360
本文介绍了使用odeint函数定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题很新手,请多多包涵。

Pretty noob question so please bear with me.

我正在遵循此处给出的示例->
http://www.codeproject.com/Articles/268589/odeint-v2-Solving-ordinary-差分方程

I am following the example given here--> http://www.codeproject.com/Articles/268589/odeint-v2-Solving-ordinary-differential-equations

我特别在看这个函数:

void lorenz( 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];
 } 

在我的情况下,R接受一系列值(具有100个双精度值的向量

In my case, R takes on a series of values (vector with 100 doubles).

odeint称为:

integrate_const( runge_kutta4< state_type >() , lorenz , x , 0.0 , 10.0 , dt );

我想为R的每个值执行此操作。如何实现此目的?我对C ++ / OOP的知识有限,但是我愿意学习。

I would like to do this for each value of R. How can I accomplish this? My knowledge of C++/OOP is limited, but I am willing to learn.

谢谢。

推荐答案

您可以使用类版本,但可以对其进行修改,以便使用您感兴趣的 R 值对其进行初始化。

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];
    }
};

然后,对向量 R 进行迭代将值传递给您传递给 integrate_const 模板函数的 lorenz_class 实例。

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 );
}

这篇关于使用odeint函数定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆