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_erfcx_real (s15ag)

## Purpose

nag_specfun_erfcx_real (s15ag) returns the value of the scaled complementary error function erfcx(x)$\mathrm{erfcx}\left(x\right)$, via the function name.

## Syntax

[result, ifail] = s15ag(x)
[result, ifail] = nag_specfun_erfcx_real(x)

## Description

nag_specfun_erfcx_real (s15ag) calculates an approximate value for the scaled complementary error function
 ∞ erfcx(x) = ex2erfc(x) = 2/(sqrt(π))ex2 ∫ e − t2 dt = ex2(1 − erf(x)). x
$erfcx(x) = e x2 erfc(x) = 2 π e x2 ∫x∞ e-t2 dt = e x2 ( 1- erf(x) ) .$
Let $\stackrel{^}{x}$ be the root of the equation erfc(x)erf(x) = 0$\mathrm{erfc}\left(x\right)-\mathrm{erf}\left(x\right)=0$ (then 0.46875$\stackrel{^}{x}\approx 0.46875$). For |x|$|x|\le \stackrel{^}{x}$ the value of erfcx(x)$\mathrm{erfcx}\left(x\right)$ is based on the following rational Chebyshev expansion for erf(x)$\mathrm{erf}\left(x\right)$:
 erf(x) ≈ xRℓ,m(x2), $erf(x)≈xRℓ,m(x2),$
where R,m${R}_{\ell ,m}$ denotes a rational function of degree $\ell$ in the numerator and m$m$ in the denominator.
For |x| > $|x|>\stackrel{^}{x}$ the value of erfcx(x)$\mathrm{erfcx}\left(x\right)$ is based on a rational Chebyshev expansion for erfc(x)$\mathrm{erfc}\left(x\right)$: for < |x|4$\stackrel{^}{x}<|x|\le 4$ the value is based on the expansion
 erfc(x) ≈ ex2Rℓ,m(x); $erfc(x)≈ex2Rℓ,m(x);$
and for |x| > 4$|x|>4$ it is based on the expansion
 erfc(x) ≈ (ex2)/x(1/(sqrt(π)) + 1/(x2)Rℓ,m(1 / x2)). $erfc(x)≈ex2x(1π+1x2Rℓ,m(1/x2)).$
For each expansion, the specific values of $\ell$ and m$m$ are selected to be minimal such that the maximum relative error in the expansion is of the order 10d${10}^{-d}$, where d$d$ is the maximum number of decimal digits that can be accurately represented for the particular implementation (see nag_machine_decimal_digits (x02be)).
Asymptotically, erfcx(x)1 / (sqrt(π)|x|)$\mathrm{erfcx}\left(x\right)\sim 1/\left(\sqrt{\pi }|x|\right)$. There is a danger of setting underflow in erfcx(x)$\mathrm{erfcx}\left(x\right)$ whenever xxhi = min (xhuge,1 / (sqrt(π)xtiny))$x\ge {x}_{\mathrm{hi}}=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left({x}_{\mathrm{huge}},1/\left(\sqrt{\pi }{x}_{\mathrm{tiny}}\right)\right)$, where xhuge${x}_{\mathrm{huge}}$ is the largest positive model number (see nag_machine_real_largest (x02al)) and xtiny${x}_{\mathrm{tiny}}$ is the smallest positive model number (see nag_machine_real_smallest (x02ak)). In this case nag_specfun_erfcx_real (s15ag) exits with ${\mathbf{ifail}}={\mathbf{1}}$ and returns erfcx(x) = 0$\mathrm{erfcx}\left(x\right)=0$. For x$x$ in the range 1 / (2sqrt(ε))x < xhi$1/\left(2\sqrt{\epsilon }\right)\le x<{x}_{\mathrm{hi}}$, where ε$\epsilon$ is the machine precision, the asymptotic value 1 / (sqrt(π)|x|)$1/\left(\sqrt{\pi }|x|\right)$ is returned for erfcx(x)$\mathrm{erfcx}\left(x\right)$ and nag_specfun_erfcx_real (s15ag) exits with ${\mathbf{ifail}}={\mathbf{2}}$.
There is a danger of setting overflow in ex2${e}^{{x}^{2}}$ whenever x < xneg = sqrt(log(xhuge / 2))$x<{x}_{\mathrm{neg}}=-\sqrt{\mathrm{log}\left({x}_{\mathrm{huge}}/2\right)}$. In this case nag_specfun_erfcx_real (s15ag) exits with ${\mathbf{ifail}}={\mathbf{3}}$ and returns erfcx(x) = xhuge$\mathrm{erfcx}\left(x\right)={x}_{\mathrm{huge}}$.
The values of xhi${x}_{\mathrm{hi}}$, 1 / (2sqrt(ε))$1/\left(2\sqrt{\epsilon }\right)$ and xneg${x}_{\mathrm{neg}}$ are given in the Users' Note for your implementation.

## References

Abramowitz M and Stegun I A (1972) Handbook of Mathematical Functions (3rd Edition) Dover Publications
Cody W J (1969) Rational Chebyshev approximations for the error function Math.Comp. 23 631–637

## Parameters

### Compulsory Input Parameters

1:     x – double scalar
The argument x$x$ of the function.

None.

None.

### Output Parameters

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

## Error Indicators and Warnings

Note: nag_specfun_erfcx_real (s15ag) may return useful information for one or more of the following detected errors or 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 ifail = 1${\mathbf{ifail}}=1$
On entry, xxhi${\mathbf{x}}\ge {x}_{\mathrm{hi}}$ (see Section [Description]). On soft failure the function value returned is 0$0$.
W ifail = 2${\mathbf{ifail}}=2$
On entry, 1 / (2sqrt(ε))x < xhi$1/\left(2\sqrt{\epsilon }\right)\le {\mathbf{x}}<{x}_{\mathrm{hi}}$ (see Section [Description]). On soft failure the function value returned is 1 / (sqrt(π)abs(x))$1/\left(\sqrt{\pi }\mathrm{abs}\left({\mathbf{x}}\right)\right)$.
W ifail = 3${\mathbf{ifail}}=3$
On entry, x < xneg${\mathbf{x}}<{x}_{\mathrm{neg}}$ (see Section [Description]). On soft failure the function value returned is the largest positive model number.

## Accuracy

The relative error in computing erfcx(x)$\mathrm{erfcx}\left(x\right)$ may be estimated by evaluating
 E = ( erfcx(x) − ex2 ∑ n = 1 ∞ Inerfc(x) )/(erfcx(x)), $E= erfcx(x) - ex2 ∑ n=1 ∞ Inerfc(x) erfcx(x) ,$
where In${I}^{n}$ denotes repeated integration. Empirical results suggest that on the interval (,2)$\left(\stackrel{^}{x},2\right)$ the loss in base b$b$ significant digits for maximum relative error is around 3.3$3.3$, while for root-mean-square relative error on that interval it is 1.2$1.2$ (see nag_machine_model_base (x02bh) for the definition of the model parameter b$b$). On the interval (2,20)$\left(2,20\right)$ the values are around 3.5$3.5$ for maximum and 0.45$0.45$ for root-mean-square relative errors; note that on these two intervals erfc(x)$\mathrm{erfc}\left(x\right)$ is the primary computation. See also Section [Accuracy] in (s15ad).

None.

## Example

```function nag_specfun_erfcx_real_example
x = [-30.0; -6.0; -4.5; -1.0; 1.0; 4.5; 6.0; 7.0e7];

result = zeros(8, 1);
ifail  = zeros(8, 1, 'int64');
for i=1:8
[result(i), ifail(i)] = nag_specfun_erfcx_real(x(i));
end
fprintf('\n       x          erfcx(x)    ifail\n');
for i=1:8
fprintf('%13.5e %13.5e     %d\n', x(i), result(i), ifail(i));
end
```
```
Warning: nag_specfun_erfcx_real (s15ag) returned a warning indicator (3)
Warning: nag_specfun_erfcx_real (s15ag) returned a warning indicator (2)

x          erfcx(x)    ifail
-3.00000e+01  1.79769e+308     3
-6.00000e+00   8.62246e+15     0
-4.50000e+00   1.24593e+09     0
-1.00000e+00   5.00898e+00     0
1.00000e+00   4.27584e-01     0
4.50000e+00   1.22485e-01     0
6.00000e+00   9.27766e-02     0
7.00000e+07   8.05985e-09     2

```
```function s15ag_example
x = [-30.0; -6.0; -4.5; -1.0; 1.0; 4.5; 6.0; 7.0e7];

result = zeros(8, 1);
ifail  = zeros(8, 1, 'int64');
for i=1:8
[result(i), ifail(i)] = s15ag(x(i));
end
fprintf('\n       x          erfcx(x)    ifail\n');
for i=1:8
fprintf('%13.5e %13.5e     %d\n', x(i), result(i), ifail(i));
end
```
```
Warning: nag_specfun_erfcx_real (s15ag) returned a warning indicator (3)
Warning: nag_specfun_erfcx_real (s15ag) returned a warning indicator (2)

x          erfcx(x)    ifail
-3.00000e+01  1.79769e+308     3
-6.00000e+00   8.62246e+15     0
-4.50000e+00   1.24593e+09     0
-1.00000e+00   5.00898e+00     0
1.00000e+00   4.27584e-01     0
4.50000e+00   1.22485e-01     0
6.00000e+00   9.27766e-02     0
7.00000e+07   8.05985e-09     2

```