传递的参数以在C 中增强odeint
passed parameters to boost odeint in C++
这个答案很有帮助,但是我想知道如何将不同类型的多个参数传递给ode模型,也许是在结构中。对于我的直接用例,我需要能够传递一个std::array<double, 6>
,两个std::vector<std::vector<double>>
和两个两个double
标量,总共要传递四个参数。在链接的示例以及harmonic_oscillator.cpp中,只有一个double
传递的参数。谢谢。
这是我需要传递给ode力模型并在速率方程式中使用的结构的示例。
struct T
{
std::array<double, 6> IC;
double S;
double M;
std::vector<std::vector<double>> C;
std::vector<std::vector<double>> WT;
};
我相信我想出了一个有效的结构解决方案,但不确定它是否具有任何可变/内存范围no-no。这是一个例子:
#include <vector>
#include <boost/numeric/odeint.hpp>
// define structure
struct T
{
std::array<double, 6> IC;
double S;
};
// force model
class harm_osc
{
struct T T1;
public:
harm_osc(struct T G) : T1(G) {}
void operator() ( const std::vector< double > &x , std::vector< double > &dxdt , const double /* t */ )
{
dxdt[0] = x[1];
dxdt[1] = -x[0] - T1.IC[0]*x[1] + T1.S;
}
};
// print integrated state solution
void write_solution( const std::vector< double > &x , const double t )
{
printf("%-6.2f %-6.2f %-6.2fn", t, x[0], x[1]);
}
// problem setup
int main()
{
std::vector< double > x(2);
x[0] = 1.0;
x[1] = 0.0;
struct T T2;
T2.IC = {0.15, 0.15, 0.15, 0.15, 0.15, 0.15};
T2.S = 0.0;
harm_osc ho(T2);
boost::numeric::odeint::integrate(ho, x, 0.0, 10.0, 0.1, write_solution);
}
相关文章:
- 无法将结构注册为增强几何体3D点
- boost odeint什么时候真正调用观测者
- 增强基于 XML class_id的反序列化
- 增强精神解析器规则以检测语句中的特殊结尾
- C++ 使用增强正则表达式库时断言崩溃
- 增强精神 X3:错误:在"..."中没有名为"大小"的类型
- 将 boost::odeint 与向量类一起使用,而无需调整向量的大小
- 如何包装(撰写)增强 hana 地图并访问括号运算符(运算符 [])?
- 有没有办法在C ++中检测汉字?(使用增强)
- 如何将增强MSM与增强信号结合使用?
- 如何使用增强::几何计算多边形的旋转固体体积?
- 复制部分文件的C++/增强方式
- Eigen::VectorXd 和 Boost::Odeint,不起作用
- 增强 ASIO 和串行端口异步读取
- 增强 Hana index_if和类型
- 增强超几何测试
- 如何修改增强 hana 结构的成员
- 增强纤维work_stealing屏障会导致段错误
- 增强循环缓冲区push_back在前面插入数据
- 传递的参数以在C 中增强odeint