我正在尝试使用odeint,这是用于解决ODE的库 http://headmyshoulder.github.io/odeint-v2/
我正在使用集成商之一,我想将一个函数作为参数传递。有1个示例,其中他们将常量参数作为参数传递 https://github.com/headmyshoulder/odeint-v2/blob/master/examples/harmonic_oscillator.cpp
class harm_osc {
double m_gam;
public:
harm_osc( double gam ) : m_gam(gam) { }
void operator() ( const state_type &x , state_type &dxdt , const double /* t */ )
{
dxdt[0] = x[1];
dxdt[1] = -x[0] - m_gam*x[1];
}
};
在我的情况下,它是一个函数而不是常量,例如像这样的东西
y'(x)= f(x)* y(x)
其中f(x)是一个函数,我将在每个循环中对其进行修改(我需要多次求解方程式),这就是为什么我想将其保留为动态参数(函数f由一个其他程序)。