This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Error function




erf(x) returns the Error Function evaluated for each element of x.


collapse all

Find the error function of a value.

ans =


Find the error function of the elements of a vector.

V = [-0.5 0 1 0.72];
ans =

   -0.5205         0    0.8427    0.6914

Find the error function of the elements of a matrix.

M = [0.29 -0.11; 3.1 -2.9];
ans =

    0.3183   -0.1236
    1.0000   -1.0000

The cumulative distribution function (CDF) of the normal, or Gaussian, distribution with standard deviation $\sigma$ and mean $\mu$ is

$$\phi(x) = \frac{1}{2} \biggl(1+\rm erf\Bigl(

Note that for increased computational accuracy, you can rewrite the formula in terms of erfc . For details, see Tips.

Plot the CDF of the normal distribution with $\mu=0$ and $\sigma=1$.

x = -3:0.1:3;
y = (1/2)*(1+erf(x/sqrt(2)));
grid on
title('CDF of normal distribution with \mu = 0 and \sigma = 1')

Where $u(x,t)$ represents the temperature at position $x$ and time $t$, the heat equation is

$$\frac{\partial u}{\partial t} = c\frac{\partial^2 u}{\partial x^2},$$

where $c$ is a constant.

For a material with heat coefficient $k$, and for the initial condition $u(x,0) = a$ for $x > b$ and $u(x,0) = 0$ elsewhere, the solution to the heat equation is

$$u(x,t) = \frac{a}{2} \biggl(\rm erf \biggl( \frac{x-b}{\sqrt{4kt}}
\biggr) \biggr).$$

For k = 2, a = 5, and b = 1, plot the solution of the heat equation at times t = 0.1, 5, and 100.

x = -4:0.01:6;
t = [0.1 5 100];
a = 5;
k = 2;
b = 1;
hold on
for i = 1:3
    u(i,:) = (a/2)*(erf((x-b)/sqrt(4*k*t(i))));
grid on
legend('t = 0.1','t = 5','t = 100','Location','best')
title('Temperatures across material at t = 0.1, t = 5, and t = 100')

Input Arguments

collapse all

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

Data Types: single | double

More About

collapse all

Error Function

The error function erf of x is


Tall Array Support

This function fully supports tall arrays. For more information, see Tall Arrays.


  • You can also find the standard normal probability distribution using the Statistics and Machine Learning Toolbox™ function normcdf. The relationship between the error function erf and normcdf is


  • For expressions of the form 1 - erf(x), use the complementary error function erfc instead. This substitution maintains accuracy. When erf(x) is close to 1, then 1 - erf(x) is a small number and might be rounded down to 0. Instead, replace 1 - erf(x) with erfc(x).

See Also

| | |

Introduced before R2006a

Was this topic helpful?