## C++ implementation of Longman's method, and special functions

Hi all,

I'm a programming newbie teaching myself C++ mainly for interest/ because I might want a real job after my physics PhD, but I have a problem in my research some code might be useful for.

I have some functions defined by integrals of the form
$$A(q)=\int db~ b* J_{0}(b*q) (exp(i*f(b))-1)$$
where I have to consider many different functions f(b), which are typically sums of products of special functions, so an analytic approach is right out. (J is a Bessel function.) My supervisor doesn't completely trust the numerics of Mathematica so he wants an independent check on the results it gives me, one where we understand the methods used. The integration runs from 0 to infinity, and the functions f(b) sometimes encounters logarithmic singularities for small arguments, and it's of course highly oscillatory, so I'd expect that any kind of standard off-the-shelf integration routine would run into problems.

Looking around I came across
http://scicomp.stackexchange.com/que...al-computation
which suggests a couple of methods tailored to oscillatory integrals over infinite regions. It seems though that if this is a standard problem that people often have, there should be some existing code in a library somewhere for it, but I can't find any. Additionally, I can't find a library of special functions that contains all the ones I need. The best I've found so far is http://www.gnu.org/software/gsl/manual/html_node/, but this doesn't have all the hypergeometric functions I need- in particular, it doesn't have 2F3 or 1F2. Can anyone recommend a good place to look for either a library for these functions or for an implementation of Longman's method for dealing with oscillatory integrals over infinite regions? As a total novice I'd rather not go trying to reinvent the wheel, badly, when the result actually matters...

Mod note: I fixed the integral in the text above.
 PhysOrg.com science news on PhysOrg.com >> King Richard III found in 'untidy lozenge-shaped grave'>> Google Drive sports new view and scan enhancements>> Researcher admits mistakes in stem cell study
 Hey muppet. There are books like the one called Numerical Recipes: http://www.nr.com/ You're problem seems rather specialized but the above kind of resource is one that is popular when you need to look for numerical routines. Also I don't know if you are going to find something that meets the specifications exactly for your type of problem. One question I have that you might want to consider is the payoff between time searching for an algorithm to get something with a desired accuracy and the time used to say evaluate the integral using a good enough algorithm with finely tuned parameters (even if this took say a week to run). If you could for example take a good algorithm with known error metrics and calculate the time it would take to run this with the adequate parameters, then this could give you an indication of whether it might be useful to run the simulation (even if you did it multiple times in parallel on different machines so that you had a few results to compare) with these parameters or to go to the trouble of searching, coding up, and finally evaluting the problem. I don't know the nature of your work and if this is a one off thing or not, but it's certainly something to consider.
 Hi chiro, Thanks for your reply. As a starting point, I've been trying to get the GNU library working. (documentation: http://linux.math.tifr.res.in/progra...l-ref_toc.html) I've been getting an error message: undefined reference to gsl_sf_bessel_J0. Looking at the .h file it tells me to include, gsl_sf_bessel_J0. is declared there, but not defined there, and I can't see it defined in any of the .h files it includes there either. I'm trying to compile it using the command g++ -Wall -L/usr/lib -lgsl -lm -lgslcblas SourceCode/gsltest.cpp -o gsltest.exe -which should I think include all the relevant libraries? (I know it's usually /usr/local/lib/; for me that's just Python seemingly. I installed the package via ubuntu software centre if that's relevant.) My code: //gsltest.cpp #include #include double test(double x); int main() { double x = 5.0; double y = gsl_sf_bessel_J0(x); std::cout<< y ; return 0; } This should be compared to http://www.gnu.org/software/gsl/manu...xample-Program - this is C code that I've tried to adapt to the C++ I'm learning. The library is also written in C, but the documentation claims that this is accounted for in the header such that it can be called from C++ code straightforwardly; I think the relevant bit of code is #ifdef __cplusplus # define __BEGIN_DECLS extern "C" { # define __END_DECLS } #else # define __BEGIN_DECLS /* empty */ # define __END_DECLS /* empty */ #endif __BEGIN_DECLS /* Regular Bessel Function J_0(x) * * exceptions: none */ double gsl_sf_bessel_J0(const double x); __END_DECLS The rest is mostly just more declarations. Can anyone help me work out how to include the actual definition of J0? EDIT: P.S. thanks mod!

## C++ implementation of Longman's method, and special functions

Usually in libraries and external packages, the library/package comes with a "super header" which includes not only all the definitions, but includes them in the right order (which is important for avoiding compilation errors).