# NAG C Library Function Document

## 1Purpose

nag_complex_airy_ai (s17dgc) 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.

## 2Specification

 #include #include
 void nag_complex_airy_ai (Nag_FunType deriv, Complex z, Nag_ScaleResType scal, Complex *ai, Integer *nz, NagError *fail)

## 3Description

nag_complex_airy_ai (s17dgc) 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 function is derived from the function 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 $\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(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 function.

## 4References

NIST Digital Library of Mathematical Functions
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

## 5Arguments

1:    $\mathbf{deriv}$Nag_FunTypeInput
On entry: specifies whether the function or its derivative is required.
${\mathbf{deriv}}=\mathrm{Nag_Function}$
$\mathrm{Ai}\left(z\right)$ is returned.
${\mathbf{deriv}}=\mathrm{Nag_Deriv}$
${\mathrm{Ai}}^{\prime }\left(z\right)$ is returned.
Constraint: ${\mathbf{deriv}}=\mathrm{Nag_Function}$ or $\mathrm{Nag_Deriv}$.
2:    $\mathbf{z}$ComplexInput
On entry: the argument $z$ of the function.
3:    $\mathbf{scal}$Nag_ScaleResTypeInput
On entry: the scaling option.
${\mathbf{scal}}=\mathrm{Nag_UnscaleRes}$
The result is returned unscaled.
${\mathbf{scal}}=\mathrm{Nag_ScaleRes}$
The result is returned scaled by the factor ${e}^{2z\sqrt{z}/3}$.
Constraint: ${\mathbf{scal}}=\mathrm{Nag_UnscaleRes}$ or $\mathrm{Nag_ScaleRes}$.
4:    $\mathbf{ai}$Complex *Output
On exit: the required function or derivative value.
5:    $\mathbf{nz}$Integer *Output
On exit: indicates whether or not ai is set to zero due to underflow. This can only occur when ${\mathbf{scal}}=\mathrm{Nag_UnscaleRes}$.
${\mathbf{nz}}=0$
ai is not set to zero.
${\mathbf{nz}}=1$
ai is set to zero.
6:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

## 6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
On entry, argument $〈\mathit{\text{value}}〉$ had an illegal value.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_OVERFLOW_LIKELY
No computation because $\omega \mathbf{.}\mathbf{re}$ too large, where $\omega =\left(2/3\right)×{{\mathbf{z}}}^{\left(3/2\right)}$.
NE_TERMINATION_FAILURE
No computation – algorithm termination condition not met.
NE_TOTAL_PRECISION_LOSS
No computation because $\left|{\mathbf{z}}\right|=〈\mathit{\text{value}}〉>〈\mathit{\text{value}}〉$.
NW_SOME_PRECISION_LOSS
Results lack precision because $\left|{\mathbf{z}}\right|=〈\mathit{\text{value}}〉>〈\mathit{\text{value}}〉$.

## 7Accuracy

All constants in nag_complex_airy_ai (s17dgc) 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 nag_complex_airy_ai (s17dgc), 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.

## 8Parallelism and Performance

nag_complex_airy_ai (s17dgc) 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 nag_airy_ai (s17agc) or nag_airy_ai_deriv (s17ajc).

## 10Example

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 used as a flag to set the argument scal. The program calls the function and prints the results. The process is repeated until the end of the input data stream is encountered.

### 10.1Program Text

Program Text (s17dgce.c)

### 10.2Program Data

Program Data (s17dgce.d)

### 10.3Program Results

Program Results (s17dgce.r)