made with Mathematica technology MathWorld

Piecewise Function

A piecewise function is a function that is defined on a sequence of intervals. A common example is the absolute value,

 |x|={-x   for x<0; 0   for x=0; x   for x>0.
(1)

Piecewise functions are implemented in Mathematica as Piecewise[{{val1, cond1}, {val2, cond2}, ...}].

Additional piecewise functions include the Heaviside step function, rectangle function, and triangle function.

A number of different notational conventions are used for denoting a piecewise function. In TeX, the command \cases is used in a construction such as

  {displaymath}
{
    -x& for $x<0$
     0& for $x=0$
     x& for $x>0$}
displaymath}%

Semicolons and commas are sometimes used at the end of either the left or the right column, with particular usage apparently depending on the author. The words "if" and "for" are sometimes used in the right column, as is "otherwise" for the final (default) case.

For example, Knuth (1996, pp. 175 and 180) uses the notations

|x|={x, if x>=0;; -x, otherwise;
(2)
f(x)={1/3 if 0<=x<=1;; 2/3 if 3<=x<=4;; 0 elsewhere
(3)
x_(2m)={Q(X_m^2-P_2W_m^2)-2S^2 (m odd); P_2^2(X_m^2-P_2W_m^2)-2S^2 (m even)
(4)

both with and without the left-column commas. Similarly, Arfken (1985, pp. 488-489) uses

 delta_n(x)={0,   x<-1/(2n); n,   -1/(2n)<x<1/(2n),; 0,   1/(2n)<x 
delta_n(x)={0,   x<0; ne^(-nx),   x>0 
lim_(a->infty)2/piint_(x_1)^(x_2)f(u+x)(sin(ax))/xdx={f(u+0)+f(u-0),   x_1<0<x_2; f(u+0),   x_1=0<x_2; f(u-0),   x_1<0=x_2; 0   x_1<x_2<0 or 0<x_1<x_2,
(5)

which lacks semicolons but only sometimes lacks right-column commas.

In this work, commas and semicolons are not used.

SEE ALSO: Heaviside Step Function, Iverson Bracket, Piecewise Constant Function, Piecewise Linear Function

REFERENCES:

Arfken, G. Mathematical Methods for Physicists, 3rd ed. Orlando, FL: Academic Press, 1985.

Knuth, D. E. The TEXBook. Boston, MA: Addison-Wesley, 1996.

Rytin, M. "Integration of Piecewise Functions with Applications." http://library/infocenter/MathSource/5117.




CITE THIS AS:

Weisstein, Eric W. "Piecewise Function." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/PiecewiseFunction.html

Mathematica For Students -- as low as $44.95.