Documentation

erfinv

Inverse error function

Syntax

erfinv(x)

Description

example

erfinv(x)returns theInverse Error Functionevaluated for each element ofx. For inputs outside the interval[-1 1],erfinvreturnsNaN.

Examples

collapse all

erfinv(0.25)
ans = 0.2253

For inputs outside[1],erfinvreturnsNaN. For-1and1,erfinvreturns-InfandInf, respectively.

erfinv([-2 -1 1 2])
ans =NaN -Inf Inf NaN

Find the inverse error function of the elements of a matrix.

M = [0 -0.5; 0.9 -0.2]; erfinv(M)
ans =0 -0.4769 1.1631 -0.1791

Plot the inverse error function for -1 < x < 1.

x = -1:0.01:1; y = erfinv(x); plot(x,y) gridonxlabel('x') ylabel('erfinv(x)') title('Inverse Error Function for -1 < x < 1')

Generate Gaussian distributed random numbers using uniformly distributed random numbers. To convert a uniformly distributed random numberto a Gaussian distributed random number, use the transform

Note that becausexhas the form-1 + 2*rand(1,10000), you can improve accuracy by using误差补函数invinstead oferfinv. For details, seeTips.

Generate 10,000 uniformly distributed random numbers on the interval[1]. Transform them into Gaussian distributed random numbers. Show that the numbers follow the form of the Gaussian distribution using a histogram plot.

rng('default') x = -1 + 2*rand(1,10000); y = sqrt(2)*erfinv(x); h = histogram(y);

Input Arguments

collapse all

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

Data Types:single|double

More About

collapse all

Inverse Error Function

The inverse error functionerfinvis defined as the inverse of the error function, such that

erfinv ( erf ( x ) ) = x .

Tips

  • For expressions of the formerfinv(1-x), use the complementary inverse error function误差补函数invinstead. This substitution maintains accuracy. Whenxis close to1, then1 - xis a small number and may be rounded down to0. Instead, replaceerfinv(1-x)with误差补函数inv(x).

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced before R2006a

Was this topic helpful?