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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -