1

Does anybody know a c++ library for numerical integration of samples (data points (x,y)), like scipy integrate.simps? I know it's not hard to implement by myself (in fact I already did), but I need to do this very often for large data sets, that's why I am looking for a maybe faster library implementation. I already checked boost and gsl, but didn't find anything!

Thanks and cheers

4
  • Why is it important to you that the library be in C++? Can't you use just any library (i.e. a .so or a .dll shared library)? Maybe this is also the reason why you haven't found one, this doesn't seem something particularly language-specific.
    – einpoklum
    May 5, 2016 at 22:44
  • 2
    Of course, any library is fine, as long as it's compatible with my code May 6, 2016 at 6:14
  • how about making your code compatible with a library ?
    – StefanS
    May 6, 2016 at 9:17
  • 1
    :-) .. also ok, but as I wrote below, writing an interpolating function to get a continuous function doesn't help, since it would slow down the calculation. Thus, I am looking for a library, function, which can handle an array, vector, whatever, with a fixed number of points! May 6, 2016 at 9:30

1 Answer 1

2

You should consider the relatively popular GNU Scientific Library (GSL), which is by the way what GCC uses internally (although not the numerical integration part).

It has a pretty long manual section on numeric integration, describing:

  • QNG non-adaptive Gauss-Kronrod integration
  • QAG adaptive integration
    • with singularities
    • with known singular points
    • on infinite intervals:
    • for Cauchy principal values:
    • for singular functions
  • adaptive integration
    • for oscillatory functions
    • for Fourier integrals
  • CQUAD doubly-adaptive integration
  • Fixed order Gauss-Legendre integration

And most/all of these seem to be sample-based (rather than integrating using some symbolic representation).

It's written in C, but it seems you're willing to accept that.

Also, Wikipedia has a long list of numerical libraries in various languages, including C and C++. I haven't much experience with numerical work in C or C++ (just a bit in MatLab), so I haven't tried any, but - you should.

If you do so, consider answering your own question and reporting which libraries fit your requirement (basically) and which you've chosen.

1
  • 1
    Thanks for your suggestion, but as far as I understand it, all the GSL numerical integration algorithms need a function (const gsl_function * f) as input. Of course I could interpolate my data points to get a continous function, but this would even slow down my calculations. None of these algorithms accept an array, or vector, of discrete points as input. May 6, 2016 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.