Main Content

erf

Error function

Syntax

Description

example

erf(X) represents the error function of X. If X is a vector or a matrix, erf(X) computes the error function of each element of X.

Examples

Error Function for Floating-Point and Symbolic Numbers

Depending on its arguments, erf can return floating-point or exact symbolic results.

Compute the error function for these numbers. Because these numbers are not symbolic objects, you get the floating-point results:

A = [erf(1/2), erf(1.41), erf(sqrt(2))]
A =
    0.5205    0.9539    0.9545

Compute the error function for the same numbers converted to symbolic objects. For most symbolic (exact) numbers, erf returns unresolved symbolic calls:

symA = [erf(sym(1/2)), erf(sym(1.41)), erf(sqrt(sym(2)))]
symA =
[ erf(1/2), erf(141/100), erf(2^(1/2))]

Use vpa to approximate symbolic results with the required number of digits:

d = digits(10);
vpa(symA)
digits(d)
ans =
[ 0.5204998778, 0.9538524394, 0.9544997361]

Error Function for Variables and Expressions

For most symbolic variables and expressions, erf returns unresolved symbolic calls.

Compute the error function for x and sin(x) + x*exp(x):

syms x
f = sin(x) + x*exp(x);
erf(x)
erf(f)
ans =
erf(x)
 
ans =
erf(sin(x) + x*exp(x))

Error Function for Vectors and Matrices

If the input argument is a vector or a matrix, erf returns the error function for each element of that vector or matrix.

Compute the error function for elements of matrix M and vector V:

M = sym([0 inf; 1/3 -inf]);
V = sym([1; -i*inf]);
erf(M)
erf(V)
ans =
[        0,  1]
[ erf(1/3), -1]
 
ans =
 erf(1)
 -Inf*1i

Special Values of Error Function

erf returns special values for particular parameters.

Compute the error function for x = 0, x = ∞, and x = –∞. Use sym to convert 0 and infinities to symbolic objects. The error function has special values for these parameters:

[erf(sym(0)), erf(sym(Inf)), erf(sym(-Inf))]
ans =
[ 0, 1, -1]

Compute the error function for complex infinities. Use sym to convert complex infinities to symbolic objects:

[erf(sym(i*Inf)), erf(sym(-i*Inf))]
ans =
[ Inf*1i, -Inf*1i]

Handling Expressions That Contain Error Function

Many functions, such as diff and int, can handle expressions containing erf.

Compute the first and second derivatives of the error function:

syms x
diff(erf(x), x)
diff(erf(x), x, 2)
ans =
(2*exp(-x^2))/pi^(1/2)
 
ans =
-(4*x*exp(-x^2))/pi^(1/2)

Compute the integrals of these expressions:

int(erf(x), x)
int(erf(log(x)), x)
ans =
exp(-x^2)/pi^(1/2) + x*erf(x)
 
ans =
x*erf(log(x)) - int((2*exp(-log(x)^2))/pi^(1/2), x)

Plot Error Function

Plot the error function on the interval from -5 to 5.

syms x
fplot(erf(x),[-5 5])
grid on

Figure contains an axes object. The axes object contains an object of type functionline.

Input Arguments

collapse all

Input, specified as a symbolic number, variable, expression, or function, or as a vector or matrix of symbolic numbers, variables, expressions, or functions.

More About

collapse all

Error Function

The following integral defines the error function:

erf(x)=2π0xet2dt

Tips

  • Calling erf for a number that is not a symbolic object invokes the MATLAB® erf function. This function accepts real arguments only. If you want to compute the error function for a complex number, use sym to convert that number to a symbolic object, and then call erf for that symbolic object.

  • For most symbolic (exact) numbers, erf returns unresolved symbolic calls. You can approximate such results with floating-point numbers using vpa.

Algorithms

The toolbox can simplify expressions that contain error functions and their inverses. For real values x, the toolbox applies these simplification rules:

  • erfinv(erf(x)) = erfinv(1 - erfc(x)) = erfcinv(1 - erf(x)) = erfcinv(erfc(x)) = x

  • erfinv(-erf(x)) = erfinv(erfc(x) - 1) = erfcinv(1 + erf(x)) = erfcinv(2 - erfc(x)) = -x

For any value x, the system applies these simplification rules:

  • erfcinv(x) = erfinv(1 - x)

  • erfinv(-x) = -erfinv(x)

  • erfcinv(2 - x) = -erfcinv(x)

  • erf(erfinv(x)) = erfc(erfcinv(x)) = x

  • erf(erfcinv(x)) = erfc(erfinv(x)) = 1 - x

References

[1] Gautschi, W. “Error Function and Fresnel Integrals.” Handbook of Mathematical Functions with Formulas, Graphs, and Mathematical Tables. (M. Abramowitz and I. A. Stegun, eds.). New York: Dover, 1972.

Version History

Introduced before R2006a

See Also

| | |