Boost C++ Libraries: Ticket #2733: Cylindrical bessel fuction gives wrong result if n=-1 and z>1 https://svn.boost.org/trac10/ticket/2733 <p> If the order of Bessel function is -1 and argument is more than 1.0 the algorithm goes on wrong branch, giving always 0 as result. Here a program to illustrate the problem: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/math/special_functions/bessel.hpp&gt; int main() { std::cout.setf (std::ios::scientific | std::ios::left); std::cout.precision(5); double z=0.99999; std::cout&lt;&lt;"z="&lt;&lt;z&lt;&lt;" J_{-1}(z)="&lt;&lt;boost::math::cyl_bessel_j(-1, z)&lt;&lt;'\n'; z=1.00007e+00; std::cout&lt;&lt;"z="&lt;&lt;z&lt;&lt;" J_{-1}(z)="&lt;&lt;boost::math::cyl_bessel_j(-1, z)&lt;&lt;'\n'; return 0; } </pre><p> The output of the program is: </p> <pre class="wiki">z=9.99990e-01 J_{-1}(z)=-4.40047e-01 z=1.00007e+00 J_{-1}(z)=-0.00000e+00 </pre><p> I have created a patch against the latest subverversion: </p> <pre class="wiki">Index: boost/math/special_functions/detail/bessel_jn.hpp =================================================================== --- boost/math/special_functions/detail/bessel_jn.hpp (revision 51047) +++ boost/math/special_functions/detail/bessel_jn.hpp (working copy) @@ -32,9 +32,12 @@ { return bessel_j0(x); } - if (n == 1) + if ((n == 1) || (n == -1)) { - return bessel_j1(x); + factor = n; // J_{-1}(z) = -1*J_1(z) + value = bessel_j1(x); + value *=factor; + return value; } if (n &lt; 0) { </pre><p> The output after the patch is: </p> <pre class="wiki">z=9.99990e-01 J_{-1}(z)=-4.40047e-01 z=1.00007e+00 J_{-1}(z)=-4.40073e-01 </pre><p> This is correspond to GNU Octave: </p> <pre class="wiki">octave:32&gt; besselj(-1,0.99999) ans = -0.44005 - 0.00000i octave:26&gt; besselj(-1,1.00007) ans = -0.44007 - 0.00000i </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2733 Trac 1.4.3 Ivan Lisenkov <ivan@…> Fri, 06 Feb 2009 08:48:53 GMT attachment set https://svn.boost.org/trac10/ticket/2733 https://svn.boost.org/trac10/ticket/2733 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">bessel_jn.patch</span> </li> </ul> Ticket Ivan Lisenkov <ivan@…> Fri, 06 Feb 2009 15:22:16 GMT component changed; owner set https://svn.boost.org/trac10/ticket/2733#comment:1 https://svn.boost.org/trac10/ticket/2733#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">John Maddock</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">math</span> </li> </ul> Ticket John Maddock Fri, 06 Feb 2009 17:26:32 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2733#comment:2 https://svn.boost.org/trac10/ticket/2733#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/51059" title="Fix bug in bessel_jn for n == -1. Add new test case. Checked that the ...">[51059]</a>) Fix bug in bessel_jn for n == -1. Add new test case. Checked that the other Bessel functions do not have the same issue. Checked that real-valued -1 argument is fixed OK as well as integer argument. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2733" title="#2733: Patches: Cylindrical bessel fuction gives wrong result if n=-1 and z&gt;1 (closed: fixed)">#2733</a>. </p> Ticket