This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Error function





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.


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);
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);
ans =
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]);
ans =
[        0,  1]
[ erf(1/3), -1]
ans =

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 =
ans =

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

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:



  • 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.


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


[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.

See Also

| | |

Introduced before R2006a