-1

I have been trying to find a library/function that computes the Bessel function of the first kind, but with non-integer values. I have the following program.

   // Include standard libraries
   #include <cstdlib>
   #include <cmath>
   #include <vector>
   #include <array>
   #include <iostream>


   int main(int nargs, char* args[])
   {
    std::cout << "bessel function " << jn(5./2., 1.) << "\n" ;
   }

However, it seems this function only calculates for integer values, so in the example I get the first Bessel function for n=2.

Anyone knows how I can determine the first Bessel function with non-integer values?

EDIT: I want to find a function in C++ that calculate J_(5/2)(x) for me.

chverb
  • 1
  • 1
  • 2+1/2 is an integer. try 2+1.0/2 instead – Humam Helfawi Jan 15 '16 at 09:03
  • I have tried 2.5 too, that doesn't work either. – chverb Jan 15 '16 at 09:04
  • What is `jn()` actually? – πάντα ῥεῖ Jan 15 '16 at 09:05
  • 3
    Are you trying to call the [POSIX function](http://linux.die.net/man/3/jn) `double jn(int n, double x);` ? If so then it is unclear why you would want to pass `2.5` to an integer parameter – M.M Jan 15 '16 at 09:05
  • Well, jn is taking only integer arguments, it seems. But I was wondering if there was a function that does take values n+1/2 for bessel functions, since I can't seem to find one. – chverb Jan 15 '16 at 09:06
  • Maybe you meant `jn(1, 2.5)` ? – M.M Jan 15 '16 at 09:07
  • No I want the Bessel function of the first kind with n=5/2. – chverb Jan 15 '16 at 09:08
  • The `j*()` and `y*()` family of functions only support the integer family of Bessel functions. [Boost Math](http://www.boost.org/doc/libs/1_60_0/libs/math/doc/html/math_toolkit/bessel/bessel_first.html) seems to have an implementation for fractionals. Including implementation details in the docs. – dhke Jan 15 '16 at 09:15
  • @chverb `n` is the order of the Bessel function. `1` means first-order, etc. There is no such thing as "2.5-th order function". – M.M Jan 15 '16 at 09:20
  • Well, it is 5/2 as order that I would like. – chverb Jan 15 '16 at 09:24

1 Answers1

1

boost library could be an answer. The Bessel function of the first kind is called cyl_bessel_j(v, x). Second kind cyl_neumann(v, x). Both works for real v.

Interesting alteranative here is the ROOT library from CERN with a lot of functions for scientific computation.

Lukáš Bednařík
  • 2,578
  • 2
  • 15
  • 30
  • I looked into Boost, but all I can find for bessel function of first kind is: T bessel_jn(int n, T x, const Policy& pol) – chverb Jan 15 '16 at 09:56
  • http://www.boost.org/doc/libs/1_52_0/libs/math/doc/sf_and_dist/html/math_toolkit/special/bessel/bessel.html – Lukáš Bednařík Jan 15 '16 at 09:58
  • I get that... But cyl_bessel_j_imp seems to check if your input is an integer: if(floor(v) == v) { T r = cyl_bessel_j_imp(v, T(-x), t, pol); if(iround(v, pol) & 1) r = -r; return r; } else return policies::raise_domain_error( function, "Got x = %1%, but we need x >= 0", x, pol); } T j, y; bessel_jy(v, x, &j, &y, need_j, pol); return j; } – chverb Jan 15 '16 at 10:07