Microsoft KB Archive/89404

= Microsoft Knowledge Base =

Excel: ATP Definition: BESSELJ
Last reviewed: January 30, 1996

Article ID: Q89404

The information in this article applies to:


 * Microsoft Excel for Windows 95, version 7.0
 * Microsoft Excel for Windows, versions 4.0, 5.0
 * Microsoft Excel for the Macintosh, versions 4.0, 5.0

SUMMARY
The versions of Microsoft Excel listed above provide a set of special analysis tools called the Analysis ToolPak. This article is part of a series of articles that provides information on the underlying formulas used in the Analysis ToolPak.

This article covers the following functions:

BESSELJ (Returns the nth order of the Bessel function J(x))

MORE INFORMATION
The following C routine is used to calculate the Bessel J function where n=0 and x is any real number:

float bessj0(x) float x;
 * 1) include 

{

float ax, z;    double xx, y, ans, ans1, ans2;

if ((ax=fabs(x)) < 8.0) {   // Direct rational function fit y=x*x; ans1=57568490574.0+y*(-13362590354.0+y*(651619640.7 +y*(-11214424.18+y*(77392.33017+y*(-184.9052456))))); ans2=57568490411.0+y*(1029532985.0+y*(9494680.718 +y*(59272.64853+y*(267.8532712+y*1.0)))); ans=ans1/ans2; } else { // Fitting function z=8.0/ax; y=z*z; xx=ax-0.785398164; ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4 +y*(-0.2073370639e-5+y*0.2093887211e-6))); ans2=-0.1562499995e-1+y*(0.1430488765e-3           +y*(-0.6911147651e-5+y*(0.7621095161e-6            -y*0.934935152e-7))); ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2); }    return ans; }

The following C routine is used to calculate the Bessel J function where n=1 and x is any real number:

float bessj1(x) float x;
 * 1) include 

{

float ax, z;    double xx, y, ans, ans1, ans2;

if ((ax=fabs(x)) < 8.0) {   // Direct rational function fit y=x*x; ans1=x*(723626614232.0+y*(-7895059235.0+y*(242396853.1           +y*(-2972611.439+y*(15704.48260+y*(-30.16036606)))))); ans2=144725228442.0+y*(2300535178.0+y*(18583304.74 +y*(99447.43394+y*(376.9991397+y*1.0)))); ans=ans1/ans2; } else { z=8.0/ax; y=z*z; xx=ax-2.356194491; ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019e-6)))); ans2=0.04687499995+y*(-0.2002690873e-3           +y*(0.8449199096e-5+y*(-0.88228987e-6            +y*0.105787412e-6))); ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2); if (x < 0.0) ans = -ans; }    return ans; }

The following C routine is used to calculate the Bessel J function where n>=2 and x is any real number:


 * 1) include 

float bessj(n,x)
 * 1) define ACC 40.0
 * 2) define BIGNO 1.0e10
 * 3) define BIGNI 1.0e-10

int n; float x;

{

int j, jsum, m;    float ax, bj, bjm, bjp, sum, tox, ans; float bessj0, bessj1; void nrerror;

if (n <2) nrerror(&quot;Index n less than 2&quot;); ax=fabs(x); if (ax == 0.0) return 0.0; else if (ax > (float)n) { // Use upwards recurrence from J0, J1          tox=2.0/ax; bjm=bessj0(ax); bj=bessj1(ax); for (j=1; j0; j--) { bjm=j*tox*bj-bjp; bjp=bj; bj=bjm; if (fabs(bj) > BIGNO) { bj *= BIGNI; bjp *= BIGNI; ans *= BIGNI; sum *= BIGNI; }              if (jsum) sum += bj; jsum=!jsum; if(j==n) ans=bjp; }         sum=2.0*sum-bj; ans /= sum; }    return x < 0.0 && n%2 == 1 ? -ans : ans; }