我试图创建一个可以像这样使用的class NumericalAntiderivative
:
auto f = [](double x){
return std::sin(x); // in general this may be a complicated expression that is not analytically integrable
};
NumericalAntiderivative ad(f,minXofInterest,maxXofInterest);
// the line above may be costly, but the line below should be efficient
std::cout << "Integral of f from 0 to 5 is " << (ad(5.0)-ad(0.0)) << std::endl;
我在this maths question中描述了一些想法,但问题可能更适合SO。我只需要一些想法/指针,这些想法/指针可能会带来实现这一目标的好方法。