使用boost :: numeric :: odeint来集成非线性函数f'(x,y,z)= a + b * I

时间:2018-02-09 17:12:58

标签: c++ boost odeint

我想使用自适应步骤方案集成一个将3D点(由TRANSFORM First(MySubQuery.Itemimage) AS FirstOfItemimage SELECT MySubQuery.Itemcode FROM (SELECT [Itemcode], 'Itemimage' & [Number] AS ColumnName, [Itemimage] FROM Table1) AS MySubQuery GROUP BY MySubQuery.Itemcode PIVOT MySubQuery.ColumnName; 参数化)映射到2D点(复平面)的函数。我的函数的导数没有封闭形式,它是非线性的。

我已尝试以下操作以查看代码是否有效。它编译但结果是错误的。正在集成的测试函数(tt0; 1是复数)是

  

Exp [-Norm [{1.1,2.4,3.6} * t] * i]

预期结果是

  

-0.217141 - 0.279002 i

i

代码输出

  

5051 + 0 i

我怀疑问题出在我对#include <iostream> #include <complex> #include <boost/numeric/ublas/vector.hpp> namespace ublas = boost::numeric::ublas; #include <boost/numeric/odeint.hpp> namespace odeint = boost::numeric::odeint; typedef std::complex<double> state_type; class Integrand { ublas::vector<double> point_; public: Integrand(ublas::vector<double> point){ point_ = point; } void operator () (const state_type &x, state_type &dxdt, const double t){ point_ *= t; const std::complex<double> I(0.0, 1.0); dxdt = std::exp( -norm_2(point_)*I ); } }; std::complex<double> integral(ublas::vector<double> pt) { typedef odeint::runge_kutta_cash_karp54< state_type > error_stepper_type; double err_abs = 1.0e-10; double err_rel = 1.0e-6; state_type x = std::complex<double>(1.0, 0.0); return odeint::integrate_adaptive( odeint::make_controlled<error_stepper_type>(err_abs, err_rel), Integrand(pt), x, 0.0, 1.0, 0.001); } int main() { ublas::vector<double> pt(3); pt(0) = 1.1; pt(1) = 2.4; pt(2) = 3.6; std::cout << integral(pt) << std::endl; return 0; } 状态向量的定义中。我不知道应该是什么。

1 个答案:

答案 0 :(得分:2)

我怀疑您的问题是因为您每次拨打Integrand::operator()时都在修改point_ *= t; dxdt = exp(-norm_2(point_)*I);

而不是:

dxdt = exp(-norm_2(point_ * t) * I);

你可能意味着:

x

当你没有要更改的成员变量时,你的Integrand :: operator()应该被标记为const函数,这有助于将来捕获这些错误。

在查看odeint的文档后,integrate_adaptive将返回执行的步骤数。输入参数odeint::integrate_adaptive( odeint::make_controlled<error_stepper_type>(err_abs, err_rel), Integrand(pt), x, 0.0, 1.0, 0.001); return x; 实际上保存了最终结果,因此您希望这样做:

(0.782859,-0.279002)

运行此打印x,这仍然不是您正在寻找的答案。您正在寻找的答案是在0而不是1处开始state_type x = std::complex<double>(0.0, 0.0); odeint::integrate_adaptive( odeint::make_controlled<error_stepper_type>(err_abs, err_rel), Integrand(pt), x, 0.0, 1.0, 0.001); return x; 的结果。

GetSecretAsyn()
相关问题