C++: Using boost to calculate simple definite integrals -
anyone know how use boost solve simple definite integrals?
e.g. -x^2 + 1 -1 1?
i have tried reading boost documentation, can't seem figure out how pass function.
thanks
edit: attempt far
using namespace boost::math; typename function_type; // wrong function_type f // , { return -x*x+1; }; int main(int, char**) { const double val = integral(0.0, 1, 0.001, f); // question is, put in here? how format f. }
the first thing observe boost library you've shown doesn't have function calculate integrals. might have set on wrong track.
the library used multi-precision floating point operations, , 1 of examples happens simple approximation of integrals, per riemann. point of example riemann integrals simple can use them demonstrate fancy library.
in case, wouldn't need bother passing function. can write out riemann method substituting -x^2 + 1
directly.
that said, typical c++ way pass argument [](double x) { return -x*x+1.0;}
. that's unnamed function or lambda. doesn't need name of own, since parameter has name.
Comments
Post a Comment