# erfcx

Scaled complementary error function

## Description

example

````erfcx(x)` returns the value of the Scaled Complementary Error Function for each element of `x`. Use the `erfcx` function to replace expressions containing `exp(x^2)*erfc(x)` to avoid underflow or overflow errors.```

## Examples

collapse all

### Find Scaled Complementary Error Function

```erfcx(5) ```
```ans = 0.1107 ```

Find the scaled complementary error function of the elements of a vector.

```V = [-Inf -1 0 1 10 Inf]; erfcx(V) ```
```ans = Inf 5.0090 1.0000 0.4276 0.0561 0 ```

Find the scaled complementary error function of the elements of a matrix.

```M = [-0.5 15; 3.2 1]; erfcx(M) ```
```ans = 1.9524 0.0375 0.1687 0.4276 ```

### Avoid Roundoff Errors Using Scaled Complementary Error Function

You can use the scaled complementary error function `erfcx` in place of `exp(x^2)*erfc(x)` to avoid underflow or overflow errors.

Show how to avoid roundoff errors by calculating `exp(35^2)*erfc(35)` using `erfcx(35)`. The original calculation returns `NaN` while `erfcx(35)` returns the correct result.

```x = 35; exp(x^2)*erfc(x) erfcx(x) ```
```ans = NaN ans = 0.0161 ```

## Input Arguments

collapse all

### `x` — Inputreal number | vector of real numbers | matrix of real numbers | multidimensional array of real numbers

Input, specified as a real number, or a vector, matrix, or multidimensional array of real numbers. `x` cannot be sparse.

Data Types: `single` | `double`

collapse all

### Scaled Complementary Error Function

The scaled complementary error function `erfcx(x)` is defined as

$\text{erfcx}\left(x\right)={e}^{{x}^{2}}\text{erfc}\left(x\right).$

For large `X`, `erfcx(X)` is approximately $\left(\frac{1}{\sqrt{\pi }}\right)\frac{1}{x}.$

### Tips

• For expressions of the form `exp(-x^2)*erfcx(x)`, use the complementary error function `erfc` instead. This substitution maintains accuracy by avoiding roundoff errors for large values of `x`.