NAG Library Routine Document
s17dgf (airy_ai_complex)
1
Purpose
s17dgf returns the value of the Airy function $\mathrm{Ai}\left(z\right)$ or its derivative ${\mathrm{Ai}}^{\prime}\left(z\right)$ for complex $z$, with an option for exponential scaling.
2
Specification
Fortran Interface
Integer, Intent (Inout)  ::  ifail  Integer, Intent (Out)  ::  nz  Complex (Kind=nag_wp), Intent (In)  ::  z  Complex (Kind=nag_wp), Intent (Out)  ::  ai  Character (1), Intent (In)  ::  deriv, scal 

3
Description
s17dgf returns a value for the Airy function $\mathrm{Ai}\left(z\right)$ or its derivative ${\mathrm{Ai}}^{\prime}\left(z\right)$, where $z$ is complex, $\pi <\mathrm{arg}z\le \pi $. Optionally, the value is scaled by the factor ${e}^{2z\sqrt{z}/3}$.
The routine is derived from the routine CAIRY in
Amos (1986). It is based on the relations
$\mathrm{Ai}\left(z\right)=\frac{\sqrt{z}{K}_{1/3}\left(w\right)}{\pi \sqrt{3}}$, and
${\mathrm{Ai}}^{\prime}\left(z\right)=\frac{z{K}_{2/3}\left(w\right)}{\pi \sqrt{3}}$, where
${K}_{\nu}$ is the modified Bessel function and
$w=2z\sqrt{z}/3$.
For very large $\leftz\right$, argument reduction will cause total loss of accuracy, and so no computation is performed. For slightly smaller $\leftz\right$, the computation is performed but results are accurate to less than half of machine precision. If $\mathrm{Re}\left(w\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
Amos D E (1986) Algorithm 644: A portable package for Bessel functions of a complex argument and nonnegative order ACM Trans. Math. Software 12 265–273
5
Arguments
 1: $\mathbf{deriv}$ – Character(1)Input

On entry: specifies whether the function or its derivative is required.
 ${\mathbf{deriv}}=\text{'F'}$
 $\mathrm{Ai}\left(z\right)$ is returned.
 ${\mathbf{deriv}}=\text{'D'}$
 ${\mathrm{Ai}}^{\prime}\left(z\right)$ is returned.
Constraint:
${\mathbf{deriv}}=\text{'F'}$ or $\text{'D'}$.
 2: $\mathbf{z}$ – Complex (Kind=nag_wp)Input

On entry: the argument $z$ of the function.
 3: $\mathbf{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}^{2z\sqrt{z}/3}$.
Constraint:
${\mathbf{scal}}=\text{'U'}$ or $\text{'S'}$.
 4: $\mathbf{ai}$ – Complex (Kind=nag_wp)Output

On exit: the required function or derivative value.
 5: $\mathbf{nz}$ – IntegerOutput

On exit: indicates whether or not
ai is set to zero due to underflow. This can only occur when
${\mathbf{scal}}=\text{'U'}$.
 ${\mathbf{nz}}=0$
 ai is not set to zero.
 ${\mathbf{nz}}=1$
 ai is set to zero.
 6: $\mathbf{ifail}$ – IntegerInput/Output

On entry:
ifail must be set to
$0$,
$1\text{or}1$. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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}}=0$ or
$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,
deriv has an illegal value:
${\mathbf{deriv}}=\u2329\mathit{\text{value}}\u232a$.
On entry,
scal has an illegal value:
${\mathbf{scal}}=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=2$

No computation because $\mathrm{Re}\left(\omega \right)$ too large,
where $\omega =\left(2/3\right)\times {{\mathbf{z}}}^{\left(3/2\right)}$.
 ${\mathbf{ifail}}=3$

Results lack precision because $\left{\mathbf{z}}\right=\u2329\mathit{\text{value}}\u232a>\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=4$

No computation because $\left{\mathbf{z}}\right=\u2329\mathit{\text{value}}\u232a>\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{ifail}}=5$

No computation – algorithm termination condition not met.
 ${\mathbf{ifail}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{ifail}}=399$
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{ifail}}=999$
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7
Accuracy
All constants in s17dgf are given to approximately $18$ digits of precision. Calling the number of digits of precision in the floatingpoint 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 s17dgf, the actual number of correct digits is limited, in general, by $ps$, where $s\approx \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,\left{\mathrm{log}}_{10}\leftz\right\right\right)$ represents the number of digits lost due to the argument reduction. Thus the larger the value of $\leftz\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.
8
Parallelism and Performance
s17dgf is not threaded in any implementation.
Note that if the function is required to operate on a real argument only, then it may be much cheaper to call
s17agf or
s17ajf.
10
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 argument
deriv, the second is a complex value for the argument,
z, and the third is a character value
to set the argument
scal. The program calls the routine and prints the results. The process is repeated until the end of the input data stream is encountered.
10.1
Program Text
Program Text (s17dgfe.f90)
10.2
Program Data
Program Data (s17dgfe.d)
10.3
Program Results
Program Results (s17dgfe.r)