S Chapter Contents
S Chapter Introduction
NAG Library Manual

NAG Library Routine DocumentS17DHF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

1  Purpose

S17DHF returns the value of the Airy function $\mathrm{Bi}\left(z\right)$ or its derivative ${\mathrm{Bi}}^{\prime }\left(z\right)$ for complex $z$, with an option for exponential scaling.

2  Specification

 SUBROUTINE S17DHF ( DERIV, Z, SCAL, BI, IFAIL)
 INTEGER IFAIL COMPLEX (KIND=nag_wp) Z, BI CHARACTER(1) DERIV, SCAL

3  Description

S17DHF returns a value for the Airy function $\mathrm{Bi}\left(z\right)$ or its derivative ${\mathrm{Bi}}^{\prime }\left(z\right)$, where $z$ is complex, $-\pi <\mathrm{arg}z\le \pi$. Optionally, the value is scaled by the factor ${e}^{\left|\mathrm{Re}\left(2z\sqrt{z}/3\right)\right|}$.
The routine is derived from the routine CBIRY in Amos (1986). It is based on the relations $\mathrm{Bi}\left(z\right)=\frac{\sqrt{z}}{\sqrt{3}}\left({I}_{-1/3}\left(w\right)+{I}_{1/3}\left(w\right)\right)$, and ${\mathrm{Bi}}^{\prime }\left(z\right)=\frac{z}{\sqrt{3}}\left({I}_{-2/3}\left(w\right)+{I}_{2/3}\left(w\right)\right)$, where ${I}_{\nu }$ is the modified Bessel function and $w=2z\sqrt{z}/3$.
For very large $\left|z\right|$, argument reduction will cause total loss of accuracy, and so no computation is performed. For slightly smaller $\left|z\right|$, the computation is performed but results are accurate to less than half of machine precision. If $\mathrm{Re}\left(z\right)$ is too large, and the unscaled function is required, there is a risk of overflow and so no computation is performed. In all the above cases, a warning is given by the routine.

4  References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Amos D E (1986) Algorithm 644: A portable package for Bessel functions of a complex argument and non-negative order ACM Trans. Math. Software 12 265–273

5  Parameters

1:     DERIV – CHARACTER(1)Input
On entry: specifies whether the function or its derivative is required.
${\mathbf{DERIV}}=\text{'F'}$
$\mathrm{Bi}\left(z\right)$ is returned.
${\mathbf{DERIV}}=\text{'D'}$
${\mathrm{Bi}}^{\prime }\left(z\right)$ is returned.
Constraint: ${\mathbf{DERIV}}=\text{'F'}$ or $\text{'D'}$.
2:     Z – COMPLEX (KIND=nag_wp)Input
On entry: the argument $z$ of the function.
3:     SCAL – CHARACTER(1)Input
On entry: the scaling option.
${\mathbf{SCAL}}=\text{'U'}$
The result is returned unscaled.
${\mathbf{SCAL}}=\text{'S'}$
The result is returned scaled by the factor ${e}^{\left|\mathrm{Re}\left(2z\sqrt{z}/3\right)\right|}$.
Constraint: ${\mathbf{SCAL}}=\text{'U'}$ or $\text{'S'}$.
4:     BI – COMPLEX (KIND=nag_wp)Output
On exit: the required function or derivative value.
5:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{DERIV}}\ne \text{'F'}$ or $\text{'D'}$. or ${\mathbf{SCAL}}\ne \text{'U'}$ or $\text{'S'}$.
${\mathbf{IFAIL}}=2$
No computation has been performed due to the likelihood of overflow, because real(Z) is too large – how large depends on the overflow threshold of the machine. This error exit can only occur when ${\mathbf{SCAL}}=\text{'U'}$.
${\mathbf{IFAIL}}=3$
The computation has been performed, but the errors due to argument reduction in elementary functions make it likely that the result returned by S17DHF is accurate to less than half of machine precision. This error exit may occur if $\mathrm{abs}\left({\mathbf{Z}}\right)$ is greater than a machine-dependent threshold value (given in the Users' Note for your implementation).
${\mathbf{IFAIL}}=4$
No computation has been performed because the errors due to argument reduction in elementary functions mean that all precision in the result returned by S17DHF would be lost. This error exit may occur if $\mathrm{abs}\left({\mathbf{Z}}\right)$ is greater than a machine-dependent threshold value (given in the Users' Note for your implementation).
${\mathbf{IFAIL}}=5$
No result is returned because the algorithm termination condition has not been met. This may occur because the parameters supplied to S17DHF would have caused overflow or underflow.

7  Accuracy

All constants in S17DHF are given to approximately $18$ digits of precision. Calling the number of digits of precision in the floating point arithmetic being used $t$, then clearly the maximum number of correct digits in the results obtained is limited by $p=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(t,18\right)$. Because of errors in argument reduction when computing elementary functions inside S17DHF, the actual number of correct digits is limited, in general, by $p-s$, where $s\approx \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\left|{\mathrm{log}}_{10}\left|z\right|\right|\right)$ represents the number of digits lost due to the argument reduction. Thus the larger the value of $\left|z\right|$, the less the precision in the result.
Empirical tests with modest values of $z$, checking relations between Airy functions $\mathrm{Ai}\left(z\right)$, ${\mathrm{Ai}}^{\prime }\left(z\right)$, $\mathrm{Bi}\left(z\right)$ and ${\mathrm{Bi}}^{\prime }\left(z\right)$, have shown errors limited to the least significant $3$ – $4$ digits of precision.

Note that if the function is required to operate on a real argument only, then it may be much cheaper to call S17AHF or S17AKF.

9  Example

This example prints a caption and then proceeds to read sets of data from the input data stream. The first datum is a value for the parameter DERIV, the second is a complex value for the argument, Z, and the third is a character value to set the parameter SCAL. The program calls the routine and prints the results. The process is repeated until the end of the input data stream is encountered.

9.1  Program Text

Program Text (s17dhfe.f90)

9.2  Program Data

Program Data (s17dhfe.d)

9.3  Program Results

Program Results (s17dhfe.r)