boost odeint を使用して高精度で多次元積分を計算するための推奨される方法は何ですか? 次のコードは、f=x*y を -1 から 2 に統合しますが、解析解に対する誤差は 1 % を超えています (gcc 4.8.2、-std=c++0x):
#include "array"
#include "boost/numeric/odeint.hpp"
#include "iostream"
using integral_type = std::array<double, 1>;
int main() {
integral_type outer_integral{0};
double current_x = 0;
boost::numeric::odeint::integrate(
[&](
const integral_type&,
integral_type& dfdx,
const double x
) {
integral_type inner_integral{0};
boost::numeric::odeint::integrate(
[¤t_x](
const integral_type&,
integral_type& dfdy,
const double y
) {
dfdy[0] = current_x * y;
},
inner_integral,
-1.0,
2.0,
1e-3
);
dfdx[0] = inner_integral[0];
},
outer_integral,
-1.0,
2.0,
1e-3,
[¤t_x](const integral_type&, const double x) {
current_x = x; // update x in inner integrator
}
);
std::cout
<< "Exact: 2.25, numerical: "
<< outer_integral[0]
<< std::endl;
return 0;
}
プリント:
Exact: 2.25, numerical: 2.19088
内部積分でより厳しい停止条件を使用する必要がありますか、これを行うためのより高速で正確な方法はありますか? ありがとう!