Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_specfun_erfc_complex (s15dd)

## Purpose

nag_specfun_erfc_complex (s15dd) computes values of the function $w\left(z\right)={e}^{-{z}^{2}}\mathrm{erfc}\left(-iz\right)$, for complex $z$.

## Syntax

[result, ifail] = s15dd(z)
[result, ifail] = nag_specfun_erfc_complex(z)

## Description

nag_specfun_erfc_complex (s15dd) computes values of the function $w\left(z\right)={e}^{-{z}^{2}}\mathrm{erfc}\left(-iz\right)$, where $\mathrm{erfc}z$ is the complementary error function
 $erfc⁡z=2π∫z∞e-t2dt,$
for complex $z$. The method used is that in Gautschi (1970) for $z$ in the first quadrant of the complex plane, and is extended for $z$ in other quadrants via the relations $w\left(-z\right)=2{e}^{-{z}^{2}}-w\left(z\right)$ and $w\left(\overline{z}\right)=\overline{w\left(-z\right)}$. Following advice in Gautschi (1970) and van der Laan and Temme (1984), the code in Gautschi (1969) has been adapted to work in various precisions up to $18$ decimal places. The real part of $w\left(z\right)$ is sometimes known as the Voigt function.

## References

Gautschi W (1969) Algorithm 363: Complex error function Comm. ACM 12 635
Gautschi W (1970) Efficient computation of the complex error function SIAM J. Numer. Anal. 7 187–198
van der Laan C G and Temme N M (1984) Calculation of special functions: the gamma function, the exponential integrals and error-like functions CWI Tract 10 Centre for Mathematics and Computer Science, Amsterdam

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{z}$ – complex scalar
The argument $z$ of the function.

None.

### Output Parameters

1:     $\mathrm{result}$ – complex scalar
The result of the function.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

W  ${\mathbf{ifail}}=1$
The real part of the result overflows, and is set to the largest safe number with the correct sign. The imaginary part of the result is meaningful.
W  ${\mathbf{ifail}}=2$
The imaginary part of the result overflows, and is set to the largest safe number with the correct sign. The real part of the result is meaningful.
W  ${\mathbf{ifail}}=3$
Both real and imaginary parts of the result overflow, and are set to the largest safe number with the correct signs.
W  ${\mathbf{ifail}}=4$
The result returned is accurate to less than half precision, due to the size of an intermediate result.
${\mathbf{ifail}}=5$
The result returned has no precision, due to the size of an intermediate result, and is set to zero.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

The accuracy of the returned result depends on the argument $z$. If $z$ lies in the first or second quadrant of the complex plane (i.e., $\mathrm{Im}\left(z\right)$ is greater than or equal to zero), the result should be accurate almost to machine precision, except that there is a limit of about $18$ decimal places on the achievable accuracy because constants in the function are given to this precision. With such arguments, ifail can only return as ${\mathbf{ifail}}={\mathbf{0}}$.
If however $\mathrm{Im}\left(z\right)$ is less than zero, accuracy may be lost in two ways; firstly, in the evaluation of ${e}^{-{z}^{2}}$, if $\mathrm{Im}\left(-{z}^{2}\right)$ is large, in which case a warning will be issued through ${\mathbf{ifail}}={\mathbf{4}}$ or ${\mathbf{5}}$; and secondly, near the zeros of the required function, where precision is lost due to cancellation, in which case no warning is given – the result has absolute accuracy rather than relative accuracy. Note also that in this half-plane, one or both parts of the result may overflow – this is signalled through ${\mathbf{ifail}}={\mathbf{1}}$, ${\mathbf{2}}$ or ${\mathbf{3}}$.

The time taken for a call of nag_specfun_erfc_complex (s15dd) depends on the argument $z$, the time increasing as $\left|z\right|\to 0.0$.
nag_specfun_erfc_complex (s15dd) may be used to compute values of $\mathrm{erfc}z$ and $\mathrm{erf}z$ for complex $z$ by the relations $\mathrm{erfc}z={e}^{-{z}^{2}}w\left(iz\right)$, $\mathrm{erf}z=1-\mathrm{erfc}z$. (For double arguments, nag_specfun_erfc_real (s15ad) and nag_specfun_erf_real (s15ae) should be used.)

## Example

This example reads values of the argument $z$ from a file, evaluates the function at each value of $z$ and prints the results.
```function s15dd_example

fprintf('s15dd example results\n\n');

z = [ 1    + 1e-9i;
-3.01 + 0.75i;
2.75 - 1.52i;
-1.33 - 0.54i];
n = size(z,1);
w = z;

for j=1:n
[w(j), ifail] = s15dd(z(j));
end

disp('         z                w(z)');
disp([z w]);

```
```s15dd example results

z                w(z)
1.0000 + 0.0000i   0.3679 + 0.6072i
-3.0100 + 0.7500i   0.0522 - 0.1838i
2.7500 - 1.5200i  -0.1015 + 0.1654i
-1.3300 - 0.5400i  -0.1839 - 0.7891i

```