\Header{Bessel}{Bessel Functions}
\alias{bessel}{Bessel}
\alias{besselI}{Bessel}
\alias{besselJ}{Bessel}
\alias{besselK}{Bessel}
\alias{besselY}{Bessel}
\alias{gammaCody}{Bessel}
\keyword{math}{Bessel}
\begin{Usage}
\begin{verbatim}
besselI(x, nu, expon.scaled = FALSE)
besselK(x, nu, expon.scaled = FALSE)
besselJ(x, nu)
besselY(x, nu)
gammaCody(x)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{x}] numeric, \eqn{\ge 0}{>= 0}.
\item[\texttt{nu}] numeric; \eqn{\ge 0}{>= 0} unless in \texttt{besselK} which
is symmetric in \texttt{nu}.  The \emph{order} of the
corresponding Bessel function.
\item[\texttt{expon.scaled}] logical; if \texttt{TRUE}, the results are
exponentially scaled in order to avoid overflow
(\eqn{I_{\nu}}{I(nu)}) or underflow (\eqn{K_{\nu}}{K(nu)}),
respectively.
\end{ldescription}
\end{Arguments}
\begin{Description}
Bessel Functions of integer and fractional order, of first
and second kind, \eqn{J_{\nu}}{J(nu)} and \eqn{Y_{\nu}}{Y(nu)}, and
Modified Bessel functions (of first and third kind),
\eqn{I_{\nu}}{I(nu)} and \eqn{K_{\nu}}{K(nu)}. 

\texttt{gammaCody} is the \eqn{(\Gamma)}{} Function as from the Specfun
package and originally used in the Bessel code.\end{Description}
\begin{Details}
The underlying code for these functions stem from \emph{Netlib},
\file{http://www.netlib.org/specfun/r[ijky]besl}.

If \texttt{expon.scaled = TRUE}, \eqn{e^{-x} I_{\nu}(x)}{exp(-x) I(x;nu)},
or \eqn{e^{x} K_{\nu}(x)}{exp(x) K(x;nu)} are returned.

\texttt{gammaCody} may be somewhat faster but less
precise and/or robust than \R's standard \texttt{\Link{gamma}}.
It is here for experimental purpose mainly, and \emph{may be defunct
very soon}.\end{Details}
\begin{Value}
numeric of the same length of \texttt{x} with the (scaled, if
\texttt{expon.scale=T}) values of the corresponding Bessel function.\end{Value}
\begin{References}
Abramowitz, M. and Stegun, I. A. (1972).\\{}
\emph{Handbook of Mathematical Functions}, Dover, New York;\\{}
Chapter 9: Bessel Functions of Integer Order.\end{References}
\begin{SeeAlso}
Other special mathematical functions, as the
\texttt{\Link{gamma}}, \eqn{\Gamma(x)}{}, and \texttt{\Link{beta}},
\eqn{B(x)}{}.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
nus <- c(0:5,10,20)

x <- seq(0,4, len= 501)
plot(x,x, ylim = c(0,6), ylab="",type='n', main = "Bessel Functions  I_nu(x)")
for(nu in nus) lines(x,besselI(x,nu=nu), col = nu+2)
legend(0,6, leg=paste("nu=",nus), col = nus+2, lwd=1)

x <- seq(0,40,len=801); yl <- c(-.8,.8)
plot(x,x, ylim = yl, ylab="",type='n', main = "Bessel Functions  J_nu(x)")
for(nu in nus) lines(x,besselJ(x,nu=nu), col = nu+2)
legend(32,-.18, leg=paste("nu=",nus), col = nus+2, lwd=1)

x0 <- 2^(-20:10)
plot(x0,x0^-8, log='xy', ylab="",type='n',
     main = "Bessel Functions  J_nu(x)  near 0\n log - log  scale")
for(nu in sort(c(nus,nus+.5))) lines(x0,besselJ(x0,nu=nu), col = nu+2)
legend(3,1e50, leg=paste("nu=", paste(nus,nus+.5, sep=",")), col=nus+2, lwd=1)

plot(x0,x0^-8, log='xy', ylab="",type='n',
     main = "Bessel Functions  K_nu(x)  near 0\n log - log  scale")
for(nu in sort(c(nus,nus+.5))) lines(x0,besselK(x0,nu=nu), col = nu+2)
legend(3,1e50, leg=paste("nu=", paste(nus,nus+.5, sep=",")), col=nus+2, lwd=1)

x <- x[x > 0]
plot(x,x, ylim=c(1e-18,1e11),log="y", ylab="",type='n',
     main = "Bessel Functions  K_nu(x)")
for(nu in nus) lines(x,besselK(x,nu=nu), col = nu+2)
legend(0,1e-5, leg=paste("nu=",nus), col = nus+2, lwd=1)

## Check the Scaling :
for(nu in nus)
   print(all(abs(1- besselK(x,nu)*exp( x) / besselK(x,nu,expo=TRUE)) < 2e-15))
for(nu in nus)
   print(all(abs(1- besselI(x,nu)*exp(-x) / besselI(x,nu,expo=TRUE)) < 1e-15))

yl <- c(-1.6, .6)
plot(x,x, ylim = yl, ylab="",type='n', main = "Bessel Functions  Y_nu(x)")
for(nu in nus){xx <- x[x > .6*nu]; lines(xx,besselY(xx,nu=nu), col = nu+2){
legend(25,-.5, leg=paste("nu=",nus), col = nus+2, lwd=1)


nus <- c(0:5,10,20)

x <- seq(0,4, len= 501)
plot(x,x, ylim = c(0,6), ylab="",type='n', main = "Bessel Functions  I_nu(x)")
for(nu in nus) lines(x,besselI(x,nu=nu), col = nu+2)
legend(0,6, leg=paste("nu=",nus), col = nus+2, lwd=1)

x <- seq(0,40,len=801); yl <- c(-.8,.8)
plot(x,x, ylim = yl, ylab="",type='n', main = "Bessel Functions  J_nu(x)")
for(nu in nus) lines(x,besselJ(x,nu=nu), col = nu+2)
legend(32,-.18, leg=paste("nu=",nus), col = nus+2, lwd=1)

x0 <- 2^(-20:10)
plot(x0,x0^-8, log='xy', ylab="",type='n',
     main = "Bessel Functions  J_nu(x)  near 0\n log - log  scale")
for(nu in sort(c(nus,nus+.5))) lines(x0,besselJ(x0,nu=nu), col = nu+2)
legend(3,1e50, leg=paste("nu=", paste(nus,nus+.5, sep=",")), col=nus+2, lwd=1)

plot(x0,x0^-8, log='xy', ylab="",type='n',
     main = "Bessel Functions  K_nu(x)  near 0\n log - log  scale")
for(nu in sort(c(nus,nus+.5))) lines(x0,besselK(x0,nu=nu), col = nu+2)
legend(3,1e50, leg=paste("nu=", paste(nus,nus+.5, sep=",")), col=nus+2, lwd=1)

x <- x[x > 0]
plot(x,x, ylim=c(1e-18,1e11),log="y", ylab="",type='n',
     main = "Bessel Functions  K_nu(x)")
for(nu in nus) lines(x,besselK(x,nu=nu), col = nu+2)
legend(0,1e-5, leg=paste("nu=",nus), col = nus+2, lwd=1)

## Check the Scaling :
for(nu in nus)
   print(all(abs(1- besselK(x,nu)*exp( x) / besselK(x,nu,expo=TRUE)) < 2e-15))
for(nu in nus)
   print(all(abs(1- besselI(x,nu)*exp(-x) / besselI(x,nu,expo=TRUE)) < 1e-15))

yl <- c(-1.6, .6)
plot(x,x, ylim = yl, ylab="",type='n', main = "Bessel Functions  Y_nu(x)")
for(nu in nus)}xx <- x[x > .6*nu]; lines(xx,besselY(xx,nu=nu), col = nu+2)}
legend(25,-.5, leg=paste("nu=",nus), col = nus+2, lwd=1)





\end{ExampleCode}
\end{Examples}

