부스트 odeint를 사용하여 다차원 적분을 높은 정확도로 계산할 때 권장되는 방법은 무엇입니까? 다음 코드는 -1 내지 2 (F) = X * Y를 통합되지만 분석 용액에 에러 대하여 1 % 이상 (GCC 4.8.2, -std = C++ 0X)이다부스트 odeint를 사용하는 정확한 다차원 적분
#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
내부 통합에서보다 엄격한 정지 조건을 사용해야합니까, 아니면이를 더 빠르고 정확하게 수행 할 수 있습니까? 감사!
감사합니다. current_x가 의도 한대로 업데이트되지 않을 수도 있다고 생각하지 않았습니다. 나는 다차원 통합에 더 적합한 라이브러리를 찾았습니다 : http://ab-initio.mit.edu/wiki/index.php/Cubature (GPL). 이 경우 최소한 9 개의 샘플만으로도 훨씬 작은 오차를 줄 수 있습니다. – user3493721