hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
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)erfcx(x), 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(π))ex2et2 dt = ex2(1erf(x)).
x
erfcx(x) = e x2 erfc(x) = 2 π e x2 x e-t2 dt = e x2 ( 1- erf(x) ) .
Let x^ be the root of the equation erfc(x)erf(x) = 0erfc(x)-erf(x)=0 (then 0.46875x^0.46875). For |x||x|x^ the value of erfcx(x)erfcx(x) is based on the following rational Chebyshev expansion for erf(x)erf(x):
erf(x)xR,m(x2),
erf(x)xR,m(x2),
where R,mR,m denotes a rational function of degree  in the numerator and mm in the denominator.
For |x| > |x|>x^ the value of erfcx(x)erfcx(x) is based on a rational Chebyshev expansion for erfc(x)erfc(x): for < |x|4x^<|x|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  and mm are selected to be minimal such that the maximum relative error in the expansion is of the order 10d10-d, where dd 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|)erfcx(x)1/(π|x|). There is a danger of setting underflow in erfcx(x)erfcx(x) whenever xxhi = min (xhuge,1 / (sqrt(π)xtiny))xxhi=min(xhuge,1/(πxtiny)), where xhugexhuge is the largest positive model number (see nag_machine_real_largest (x02al)) and xtinyxtiny is the smallest positive model number (see nag_machine_real_smallest (x02ak)). In this case nag_specfun_erfcx_real (s15ag) exits with ifail = 1ifail=1 and returns erfcx(x) = 0erfcx(x)=0. For xx in the range 1 / (2sqrt(ε))x < xhi1/(2ε)x<xhi, where εε is the machine precision, the asymptotic value 1 / (sqrt(π)|x|)1/(π|x|) is returned for erfcx(x)erfcx(x) and nag_specfun_erfcx_real (s15ag) exits with ifail = 2ifail=2.
There is a danger of setting overflow in ex2ex2 whenever x < xneg = sqrt(log(xhuge / 2))x<xneg=-log(xhuge/2). In this case nag_specfun_erfcx_real (s15ag) exits with ifail = 3ifail=3 and returns erfcx(x) = xhugeerfcx(x)=xhuge.
The values of xhixhi, 1 / (2sqrt(ε))1/(2ε) and xnegxneg 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 xx of the function.

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     result – double scalar
The result of the function.
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=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 = 1ifail=1
On entry, xxhixxhi (see Section [Description]). On soft failure the function value returned is 00.
W ifail = 2ifail=2
On entry, 1 / (2sqrt(ε))x < xhi1/(2ε)x<xhi (see Section [Description]). On soft failure the function value returned is 1 / (sqrt(π)abs(x))1/(πabs(x)).
W ifail = 3ifail=3
On entry, x < xnegx<xneg (see Section [Description]). On soft failure the function value returned is the largest positive model number.

Accuracy

The relative error in computing erfcx(x)erfcx(x) 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 InIn denotes repeated integration. Empirical results suggest that on the interval (,2)(x^,2) the loss in base bb significant digits for maximum relative error is around 3.33.3, while for root-mean-square relative error on that interval it is 1.21.2 (see nag_machine_model_base (x02bh) for the definition of the model parameter bb). On the interval (2,20)(2,20) the values are around 3.53.5 for maximum and 0.450.45 for root-mean-square relative errors; note that on these two intervals erfc(x)erfc(x) is the primary computation. See also Section [Accuracy] in (s15ad).

Further Comments

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


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013