erfcx

Scaled complementary error function, exp(x^2) times erfc(x).

Category: Mathematics > Elementary Math

Syntax

Y = erfcx(X)

Evaluates exp(X.^2) .* erfc(X) for each element of X, without the overflow or underflow that the direct formula suffers.

Description

For large positive X, erfc(X) is so small that it underflows to zero, and exp(X^2) is so large that it overflows. Their product, however, is a perfectly ordinary number that decays slowly like 1/(X*sqrt(pi)). erfcx computes that product directly, so it stays accurate where the naive expression returns NaN or 0.

It is the natural building block for the Mills ratio, the Voigt profile and tail probabilities of the normal distribution.

Input arguments

X
Real array.

Output arguments

Y
Array of the same size as X.

Example

Stable for large arguments

erfcx([0 1 10 100])
x = 30;
exp(x^2) * erfc(x)
erfcx(x)
Output
ans = 1×4

    1.0000    0.4276    0.0561    0.0056
ans = NaN
ans = 0.0188

The direct product fails at x = 30, while erfcx stays accurate.

See also

erf erfc erfcinv erfinv exp