Monday, August 3, 2009

erf, erfc, erfcx, erfinv, erfcinv

Error functions

Syntax

  • Y = erf(X)             Error function
    Y = erfc(X) Complementary error function
    Y = erfcx(X) Scaled complementary error function
    X = erfinv(Y) Inverse error function
    X = erfcinv(Y) Inverse complementary error function

Definition

The error function erf(X) is twice the integral of the Gaussian distribution with 0 mean and variance of .

The complementary error function erfc(X) is defined as

The scaled complementary error function erfcx(X) is defined as

For large X, erfcx(X) is approximately

Description

Y = erf(X) returns the value of the error function for each element of real array X.

Y = erfc(X) computes the value of the complementary error function.

Y = erfcx(X) computes the value of the scaled complementary error function.

X = erfinv(Y) returns the value of the inverse error function for each element of Y. Elements of Y must be in the interval [-1 1]. The function erfinv satisfies for and .

X = erfcinv(Y) returns the value of the inverse of the complementary error function for each element of Y. Elements of Y must be in the interval [0 2]. The function erfcinv satisfies for and .

Remarks

The relationship between the complementary error function erfc and the standard normal probability distribution returned by the Statistics Toolbox function normcdf is

The relationship between the inverse complementary error function erfcinv and the inverse standard normal probability distribution returned by the Statistics Toolbox function norminv is

Examples

erfinv(1) is Inf

erfinv(-1) is -Inf.

For abs(Y) > 1, erfinv(Y) is NaN.



error

Display error messages

Syntax

  • error('message')
    error('message',a1,a2, ...)
    error('message_id','message')
    error('message_id','message',a1,a2,...)

Description

error('message') displays an error message and returns control to the keyboard. The error message contains the input string message.

The error command has no effect if message is a null string.

error('message',a1,a2,...) displays a message string that contains formatting conversion characters, such as those used with the MATLAB sprintf function. Each conversion character in message is converted to one of the values a1, a2, ... in the argument list.

    Note MATLAB converts special characters (like \n and %d) in the error message string only when you specify more than one input argument with error. See Example 3 below.

error('message_id','message') attaches a unique message identifier, or message_id, to the error message. The identifier enables you to better identify the source of an error.

error('message_id','message',a1,a2, ...) includes formatting conversion characters in message, and the character translations a1, a2, ...

Examples

Example 1

The error function provides an error return from M-files:

  • function foo(x,y)
    if nargin ~= 2
    error('Wrong number of input arguments')
    end

The returned error message looks like this:

  • foo(pi)

    ??? Error using ==> foo
    Wrong number of input arguments

Example 2

Specify a message identifier and error message string with error:

  • error('MyToolbox:angleTooLarge', ...
    'The angle specified must be less than 90 degrees.');

In your error handling code, use lasterr to determine the message identifier and error message string for the failing operation:

  • [errmsg, msgid] = lasterr
    errmsg =
    The angle specified must be less than 90 degrees.
    msgid =
    MyToolbox:angleTooLarge

Example 3

MATLAB converts special characters (like \n and %d) in the error message string only when you specify more than one input argument with error. In the single argument case shown below, \n is taken to mean backslash-n. It is not converted to a newline character:

  • error('In this case, the newline \n is not converted.')
    ??? In this case, the newline \n is not converted.

But, when more than one argument is specified, MATLAB does convert special characters. This holds true regardless of whether the additional argument supplies conversion values or is a message identifier:

  • error('ErrorTests:convertTest', ...
    'In this case, the newline \n is converted.')
    ??? In this case, the newline
    is converted.






errorbar

Plot error bars along a curve

Syntax

  • errorbar(Y,E)
    errorbar(X,Y,E)
    errorbar(X,Y,L,U)
    errorbar(...,LineSpec)
    h = errorbar(...)

Description

Error bars show the confidence level of data or the deviation along a curve.

errorbar(Y,E) plots Y and draws an error bar at each element of Y. The error bar is a distance of E(i) above and below the curve so that each bar is symmetric and 2*E(i) long.

errorbar(X,Y,E) plots X versus Y with symmetric error bars 2*E(i) long. X, Y, E must be the same size. When they are vectors, each error bar is a distance of E(i) above and below the point defined by (X(i),Y(i)). When they are matrices, each error bar is a distance of E(i,j) above and below the point defined by (X(i,j),Y(i,j)).

errorbar(X,Y,L,U) plots X versus Y with error bars L(i)+U(i) long specifying the lower and upper error bars. X, Y, L, and U must be the same size. When they are vectors, each error bar is a distance of L(i) below and U(i) above the point defined by (X(i),Y(i)). When they are matrices, each error bar is a distance of L(i,j) below and U(i,j) above the point defined by (X(i,j),Y(i,j)).

errorbar(...,LineSpec) draws the error bars using the line type, marker symbol, and color specified by LineSpec.

h = errorbar(...) returns a vector of handles to line graphics objects.

Remarks

When the arguments are all matrices, errorbar draws one line per matrix column. If X and Y are vectors, they specify one curve.

Examples

Draw symmetric error bars that are two standard deviation units in length.

  • X = 0:pi/10:pi;
    Y = sin(X);
    E = std(Y)*ones(size(X));
    errorbar(X,Y,E)









errordlg

Create and display an error dialog box

Syntax

  • errordlg
    errordlg('errorstring')
    errordlg('errorstring','dlgname')
    errordlg('errorstring','dlgname','on')
    h = errordlg(...)

Description

errordlg creates an error dialog box, or if the named dialog exists, errordlg pops the named dialog in front of other windows.

errordlg displays a dialog box named 'Error Dialog' that contains the string 'This is the default error string.'

errordlg('errorstring') displays a dialog box named 'Error Dialog' that contains the string 'errorstring'.

errordlg('errorstring','dlgname') displays a dialog box named 'dlgname' that contains the string 'errorstring'.

errordlg('errorstring','dlgname','on') specifies whether to replace an existing dialog box having the same name. 'on' brings an existing error dialog having the same name to the foreground. In this case, errordlg does not create a new dialog.

h = errordlg(...) returns the handle of the dialog box.

Remarks

MATLAB sizes the dialog box to fit the string 'errorstring'. The error dialog box has an OK pushbutton and remains on the screen until you press the OK button or the Return key. After pressing the button, the error dialog box disappears.

The appearance of the dialog box depends on the windowing system you use.

Examples

The function

  • errordlg('File not found','File Error');

displays this dialog box:

No comments:

Post a Comment