Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]

BESELJ


Syntax | Return Value | Arguments | Keywords | Examples | Version History | See Also

The BESELJ function returns the J Bessel function of order N for the argument X. The BESELJ function is adapted from "SPECFUN - A Portable FORTRAN Package of Special Functions and Test Drivers", W. J. Cody, Algorithm 715, ACM Transactions on Mathematical Software, Vol 19, No. 1, March 1993.

Syntax

Result = BESELJ(X, N [, /DOUBLE] [, ITER=variable])

Return Value

If both arguments are scalars, the function returns a scalar. If both arguments are arrays, the function matches up the corresponding elements of X and N, returning an array with the same dimensions as the smallest array. If one argument is a scalar and the other argument is an array, the function uses the scalar value with each element of the array, and returns an array with the same dimensions as the smallest input array.

If X is double-precision, the result is double-precision, otherwise the result is single-precision.

Note
If the function does not converge for an element of X, the corresponding element of the Result array will be set to the IEEE floating-point value NaN.

Arguments

X

A scalar or array specifying the values for which the Bessel function is required. Values for X must be in the range 0 to 108.

N

A scalar or array specifying the order of the Bessel function to calculate. Values for N should be greater than or equal to 0, and can be either integers or real numbers.

Keywords

DOUBLE

Set this keyword equal to one to return a double-precision result, or to zero to return a single-precision result. The computations will always be done using double precision. The default is to return a single-precision result if both inputs are single precision, and to return a double-precision result in all other cases.

ITER

Set this keyword equal to a named variable that will contain the number of iterations performed. If the routine converged, the stored value will be equal to the order N. If X or N are arrays, ITER will contain a scalar representing the maximum number of iterations.

Note
If the routine did not converge for an element of X, the corresponding element of the Result array will be set to the IEEE floating-point value NaN, and ITER will contain the largest order that would have converged for that X value.

Examples

Example 1

The following example plots the J and Y Bessel functions for orders 0, 1, and 2:

X = FINDGEN(100)/10 
 
;Plot J and Y Bessel Functions: 
PLOT, X, BESELJ(X, 0), TITLE = 'J and Y Bessel Functions' 
OPLOT, X, BESELJ(X, 1) 
OPLOT, X, BESELJ(X, 2) 
OPLOT, X, BESELY(X, 0), LINESTYLE=2 
OPLOT, X, BESELY(X, 1), LINESTYLE=2 
OPLOT, X, BESELY(X, 2), LINESTYLE=2 
 
;Annotate plot: 
xcoords = [1, 1.66, 3, .7, 1.7, 2.65] 
ycoords = [.8, .62,.52, -.42, -.42, -.42] 
labels = ['!8J!X!D0','!8J!X!D1','!8J!X!D2','!8Y!X!D0', 
   '!8Y!X!D1','!8Y!X!D2'] 
XYOUTS, xcoords, ycoords, labels, /DATA 

This results in the following plot:

Example 2

Different order Bessel functions have recurrence relationships to each other. These relationships can be used to determine how accurately IDL is computing the Bessel functions. In the following example, the recurrence relationships for each order are set to zero and the left side of the equations are plotted. The plots show how close the left side of the equations are to zero, and therefore, how accurate IDL's computation of the Bessel functions are.

This example uses the following recurrence relationship:

where J(x) is the Bessel function of the first kind of order n -1, n, or n + 1. (Similar recurrence relationships could be used for the other forms of the Bessel function.) Results are plotted for n equal to 1 through 6.

PRO AnalyzingBESELJ 
 
; Derive x values. 
x = (DINDGEN(1000) + 1.)/100. 
 
; Initialize display window. 
WINDOW, 0, TITLE = 'Bessel Functions' 
 
; Display the first 8 orders of the Bessel function of 
; the first kind. 
PLOT, x, BESELJ(x, 0), /XSTYLE, /YSTYLE, $ 
   XTITLE = 'x', YTITLE = 'f(x)', $ 
   TITLE = 'Bessel Functions of the First Kind' 
OPLOT, x, BESELJ(x, 1), LINESTYLE = 1 
OPLOT, x, BESELJ(x, 2), LINESTYLE = 2 
OPLOT, x, BESELJ(x, 3), LINESTYLE = 3 
OPLOT, x, BESELJ(x, 4), LINESTYLE = 4 
OPLOT, x, BESELJ(x, 5), LINESTYLE = 5 
OPLOT, x, BESELJ(x, 6), LINESTYLE = 0 
OPLOT, x, BESELJ(x, 7), LINESTYLE = 1 
 
; Initialize display window for recurrence relations. 
WINDOW, 1, XSIZE = 896, YSIZE = 512, $ 
   TITLE = 'Testing the Recurrence Relations' 
 
!P.MULTI = [0, 2, 3, 0, 0] 
 
; Initialize title variable. 
nString = ['0', '1', '2', '3', '4', '5', '6', '7'] 
 
; Display recurrence relationships for order 1 to 6. 
; NOTE:  the results of these relationships should be 
; very close to zero. 
FOR n = 1, 6 DO BEGIN 
   equation = x*(BESELJ(x, (n - 1)) + $ 
      BESELJ(x, (n + 1))) - 2.*FLOAT(n)*BESELJ(x, n) 
   PLOT, x, equation, /XSTYLE, /YSTYLE, CHARSIZE = 1.5, $ 
      TITLE = 'n = ' + nString[n] + ':  Orders of ' + $ 
      nString[n - 1] + ', ' + nString[n] + ', and ' + $ 
      nString[n + 1] 
   PRINT, 'n = ' + nString[n] + ':  ' 
   PRINT, 'minimum = ', MIN(equation) 
   PRINT, 'maximum = ', MAX(equation) 
ENDFOR 
 
; Return display window back to its default setting, one 
; display per window. 
 
!P.MULTI = 0 
 
END 

The results for this example are shown in the following figure.

All of these plots show that this Bessel function is calculated accurately within machine tolerance.

Version History

Introduced: Original

DOUBLE and ITER keywords: 5.6

See Also

BESELI, BESELK, BESELY


Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]